CSharp examples for System:DateTime Format
To Date from String by various format
using System.Globalization; using System;/*from www. ja v a2 s . c om*/ public class Main{ public static DateTime ToDate(this string stringDate) { if (string.IsNullOrEmpty(stringDate)) return DateTime.MinValue; return DateTime.ParseExact(stringDate, new[] { "yyyyMMdd", "yyyy-MM-dd", "yyyy/MM/dd", "yyyy.MM.dd", "yyyyMd", "yyyy-M-d", "yyyy/M/d", "yyyy.M.d" }, null, DateTimeStyles.None); } }