问题描述
如何将这个 7/3/2015 12:40:02 PM
转换为格式为的日期时间dd / MM / yyyy hh: mm:ss tt
我已经这样做了:
BreackEndTime = DateTime.ParseExact(configViewModel。 EndPause,dd / MM / yyyy hh:mm:ss tt,CultureInfo.InvariantCulture);
但我总是得到
由于月和日可以有一个数字使用
BreackEndTime = DateTime.ParseExact(configViewModel.EndPause,d / M / yyyy hh:mm:ss tt,CultureInfo不变文化);
(示例,的作品相似)
更新
由于小时还可以使用一位数字:
DateTime.ParseExact(7/3/2015 1:52:16 PM,d / M / yyyy h:mm:ss tt,CultureInfo.InvariantCulture);`
/ pre>
...所以
d / M / yyyy h:mm:ss tt
code>d / M / yyyy hh:mm:ss tt。请注意,这同样适用于分钟和秒,如果它们也可以使用单个数字,则使用d / M / yyyy h:m:s tt
。我希望你现在得到点。How can I convert this
7/3/2015 12:40:02 PM
to DateTime with format"dd/MM/yyyy hh:mm:ss tt"
I have done like this:BreackEndTime = DateTime.ParseExact(configViewModel.EndPause, "dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
But I always get
解决方案Since months and days can have a single digit use
BreackEndTime = DateTime.ParseExact(configViewModel.EndPause, "d/M/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
The "M" Custom Format Specifier (exemplary,
d
works similar)Update
Since the hour can also have a single digit you have to use:
DateTime.ParseExact("7/3/2015 1:52:16 PM", "d/M/yyyy h:mm:ss tt", CultureInfo.InvariantCulture);`
... so
"d/M/yyyy h:mm:ss tt"
instead of"d/M/yyyy hh:mm:ss tt"
. Note that the same applies to the minutes and seconds, if they also can have single digits use"d/M/yyyy h:m:s tt"
. I hope you got the point now.这篇关于将字符串转换为日期时间dd / MM / yyyy hh:mm:ss tt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!