从字符串SS.FFF为DateTime在C#:转换DD / MM / YYYY HH:MM [英] Convert dd/MM/yyyy hh:mm:ss.fff from String to DateTime in C#
本文介绍了从字符串SS.FFF为DateTime在C#:转换DD / MM / YYYY HH:MM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想转换
以下格式的串
DD / MM / YYYY HH:MM:SS.FFF
到DateTime值
I am trying to convert a string of the below format dd/MM/yyyy hh:mm:ss.fff into DateTime value
最简单的方法?
BTW
IFormatProvider culture = new CultureInfo("en-US", true);
DateTime.ParseExact(timeString, "dd/MM/yyyy hh:mm:ss.fff",culture);
抛出无效时异常
例如。
2009/11/12 13:30:00.000
其中,12月份(我知道怪异)
Eg. 11/12/2009 13:30:00.000 Where 12 is the month (i know weird)
推荐答案
您必须使用 HH
string timeString = "11/12/2009 13:30:00.000";
IFormatProvider culture = new CultureInfo("en-US", true);
DateTime dateVal = DateTime.ParseExact(timeString, "dd/MM/yyyy HH:mm:ss.fff", culture);
这篇关于从字符串SS.FFF为DateTime在C#:转换DD / MM / YYYY HH:MM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文