C#字符串转化为时间

  • Post author:
  • Post category:其他

C#字符串转化为时间

**第一种方法**
			 string timeStr = "2019-08-28";
			DateTime yesTime = Convert.ToDateTime(timeStr);

 **第二种:**
            DateTimeFormatInfo timeForInfo = new DateTimeFormatInfo();
            timeForInfo.ShortDatePattern = "yyyy/MM/dd";
            string timeStr1 = "2018-09-08";
            var time = Convert.ToDateTime(timeStr1, timeForInfo);
            
**第三种:**
            string dateString = "20190526";
            DateTime dt = DateTime.ParseExact(dateString, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);

版权声明:本文为qq_24025219原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。