Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private DateTime ParseDateTime()
- {
- try
- {
- if (m_Value is DateTime)
- return (DateTime)m_Value;
- else if (m_Value is TimeSpan)
- {
- TimeSpan ts = (TimeSpan)m_Value;
- return new DateTime(ts.Ticks);
- }
- return Convert.ToDateTime(m_Value);
- }
- catch (Exception ex)
- {
- // this is the format exception - we will test
- // one of most common date representations - [YY]YYMMDD
- string strText = m_Value.ToString();
- try
- {
- return DateTime.ParseExact(
- strText,
- new string[] {
- "MM/dd/yy",
- "MM/dd/yyyy",
- "yyyyMMdd",
- "yyMMdd",
- "yyyy-MM-dd",
- "yyyy-MM-ddTHH:mm:ss",
- "HHmm",
- "HHmmss",
- "HHmmssfff",
- "HH:mm",
- "HH:mm:ss",
- "HH:mm:ss:fff",
- "HH:mm:ss.fff",
- "MMM dd HH:mm",
- "MMM dd yyyy"
- },
- CultureInfo.InvariantCulture,
- DateTimeStyles.None
- );
- }
- catch
- {
- throw ex; // the format was not confirmed - rethrow original exception
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement