字符串到DateTime的转换 [英] String to DateTime convertion

查看:76
本文介绍了字符串到DateTime的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串"1957-08-27 12:00:00.000"
我想将其转换为格式为27/08/1957的日期和时间(不需要时间部分).

I have a string "1957-08-27 12:00:00.000"
I want to convert this to Dateandtime of format 27/08/1957 (Time part is not required).
How do I do this?

推荐答案

^ ]方法或其他任何Parse()方法.
Start with the DateTime.TryParse()[^] method, or any of the other Parse() methods.


分析提出上述问题的可行性?

在问题的正文中,有122 个字符(不带空格),

(假设)
如果每个字符都需要.1秒来键入,那么它将出现在.1x122=12.2 seconds上.

问题本身是26 个字符(,没有任何空格),因此将是.1x26 = 2.6 seconds.

根据互联网速度和对Codeproject的问问题"部分的熟悉程度,我认为还需要另外1分钟来提交问题(OP).

首先,使用代码项目的问题回答时间频率的基本假设(不使用任何预测或学习算法来计算时间频率),我假设它将花费至少(至少)5分钟的时间得到答案.

所以一起出现在5mins + 12.2 seconds + 2.6 seconds = 5mins 14.8 seconds.

我在 www.google.com [ ^ ]网站,它将显示.39 seconds中的12,900,000结果(取决于我的互联网速度)

我仍然相信这将节省OP的大量时间,并提高他们的研究技能,以找到问题的解决方案.
Analysis of the feasibility of asking the above Question?

In the body of the questions there are 122 characters (without any spaces),

(Assume)
If each character take .1 seconds to type so that will come up .1x122=12.2 seconds.

The question itself 26 characters (without any spaces) so that will be .1x26 = 2.6 seconds.

And Depending the internet speed and familiarity of the Codeproject’s ask a questions section, I would assume it will take another 1 mins to submit the questions (OP).

On top using the based assumption (without using any prediction or learning algorithm for calculating the time frequency) of the Codeproject’s question answer time frequency I would assume it will take another (at least) 5 mins to get a answer back.

So it comes up al together 5mins + 12.2 seconds + 2.6 seconds = 5mins 14.8 seconds.

Where as while I type the question in the www.google.com[^] website it will come up the 12,900,000 results within .39 seconds (depending on my internet speed)

Still I would believe this will save OP’s lots of time and as well as improve their research skills to find out the solution for a problem.


如果您从数据库中获取日期,则可以使用以上在存储过程中查询

此链接将为您提供有关日期时间格式的更多信息...
http://www.technoreader.com/SQL-Server-Date-Time-Format.aspx [ ^ ]
或者您可以使用此ShorDateTime函数
If You are getting Date From Database You can use the above Query in stored procedure

This link Wil give You More Info About Date Time Formatting...
http://www.technoreader.com/SQL-Server-Date-Time-Format.aspx[^]
or You can use this ShorDateTime Function
string to_date2;
to_date2 = DateTime.Now.ToShortDateString();
DateTime today;
today = DateTime.Parse(to_date2);
string to_day;
to_day = today.ToString(("yyyy-MM-dd"));


这篇关于字符串到DateTime的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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