fork(18) download
  1. /******************************************************************
  2.  * 创建人:HTL
  3.  * 创建时间:2015-04-08 15:36:35
  4.  * 说明:C# 使用DateTime.TryParseExact将自定义日期类型转换成日期
  5.  * Email:huangyuan413026@163.com
  6.  *******************************************************************/
  7.  
  8. using System;
  9.  
  10. public class DateTime_TryParseExact_Demo
  11. {
  12. public static void Main()
  13. {
  14. string str = DateTime.Now.ToString("yyyyMMdd");
  15. string[] format = {"yyyyMMdd"};
  16. DateTime date;
  17.  
  18. if (DateTime.TryParseExact(str,
  19. format,
  20. System.Globalization.CultureInfo.InvariantCulture,
  21. System.Globalization.DateTimeStyles.None,
  22. out date))
  23. {
  24. Console.WriteLine("Custom DateTime Type Convert success:"+date.ToString());
  25. }
  26. else
  27. Console.WriteLine("Custom DateTime Type Convert error ");
  28. }//end Main
  29. }//end
Success #stdin #stdout 0.07s 24456KB
stdin
Standard input is empty
stdout
Custom DateTime Type Convert success:4/8/2015 12:00:00 AM