欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#、.Net中把字符串(String)格式轉換為DateTime類型的三種方法

 更新時間:2015年07月04日 10:11:35   投稿:junjie  
這篇文章主要介紹了C#、.Net中把字符串(String)格式轉換為DateTime類型的三種方法,本文總結了Convert.ToDateTime(string)、Convert.ToDateTime(string, IFormatProvider)、DateTime.ParseExact()三種方法,需要的朋友可以參考下

方式一:Convert.ToDateTime(string)

復制代碼 代碼如下:

Convert.ToDateTime(string)

注意:string格式有要求,必須是yyyy-MM-dd hh:mm:ss

 方式二:Convert.ToDateTime(string, IFormatProvider)

復制代碼 代碼如下:

DateTimeFormatInfo dtFormat = new System.GlobalizationDateTimeFormatInfo();
dtFormat.ShortDatePattern = "yyyy/MM/dd";
DateTime  dt = Convert.ToDateTime("2014/10/10", dtFormat);

說明:任意格式可自定義規(guī)則。

 方式三:DateTime.ParseExact()

復制代碼 代碼如下:

string dateString = "20141010";
DateTime dt = DateTime.ParseExact(dateString, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);

說明:任意格式可自定義規(guī)則,效果同方式二。

相關文章

最新評論