如何删除字符串的结尾部分。 [英] How to I remove the ending part of a string.

查看:82
本文介绍了如何删除字符串的结尾部分。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp.net 2012 c#

我在MSSql数据库中有05/09/1994当我尝试接收它时我得到的是5/9/1994 12:00:00。



我想找到05/09/1994的最佳方式。请记住,有时会有10个字符12/12/2012,有时候是8 2/2/2012。



我尝试了什么:



I am using asp.net 2012 c#
I have 05/09/1994 in a MSSql database when I try to receive it I am getting 5/9/1994 12:00:00.

I am trying to figure the best way to 05/09/1994. Keeping in mind that sometimes there will be 10 characters 12/12/2012 and sometimes 8 2/2/2012.

What I have tried:

DateTime DateApp = ((DateTime)reader["DateOFEntry"]).Date;
     string strdate = DateApp.ToString();//get  5/9/1994  instead of  5/9/1994 12:00:00

推荐答案

您不想删除字符串的结尾部分,您希望将格式参数传递给ToString()方法,以便以您需要的格式返回日期。



例如
you do not want to remove the end part of the string, you want to pass a format parameter into the ToString() method to return the date in the format you require.

e.g.
string strdate = DateApp.ToString("d");





见:



标准日期时间格式字符串 [ ^ ]







日期/时间格式 [< a href =https://www.dotnetperls.com/datetime-formattarget =_ blanktitle =新窗口> ^ ]


这篇关于如何删除字符串的结尾部分。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆