Mega Code Archive

 
Categories / C# / Date Time
 

Converts the specified date and time strings to their DateTime equivalent representation

using System; using System.Xml; namespace SnapDragon.ECommerce.Shipping {   /// <summary>   /// Provides extensions methods for parsing xml.   /// </summary>   internal static class TrackingUtil   {         /// <summary>     /// Converts the specified date and time strings to their <see cref="DateTime"/> equivalent representation.     /// </summary>     /// <param name="pDate"></param>     /// <param name="pTime"></param>     /// <param name="pResult"></param>     /// <returns></returns>     public static bool TryParseDateTime(string pDate, string pTime, out DateTime? pResult)     {       DateTime tmpVal;       if (TryParseDateTime(pDate, pTime, out tmpVal))       {         pResult = tmpVal;         return true;       }       pResult = null;       return false;     }     /// <summary>     /// Converts the specified date and time strings to their <see cref="DateTime"/> equivalent representation.     /// </summary>     /// <param name="pDate"></param>     /// <param name="pTime"></param>     /// <param name="pResult"></param>     /// <returns></returns>     public static bool TryParseDateTime(string pDate, string pTime, out DateTime pResult)     {       if (string.IsNullOrEmpty(pDate) || string.IsNullOrEmpty(pTime))       {         pResult = DateTime.MinValue;         return false;       }       string dateTimeFormat = string.Format("{0}/{1}/{2}", pDate.Substring(6, 2),                                              pDate.Substring(4, 2), pDate.Substring(0, 4));       dateTimeFormat = string.Format("{0} {1}:{2}:{3}", dateTimeFormat,                                       pTime.Substring(0, 2), pTime.Substring(2, 2), pTime.Substring(4, 2));       return DateTime.TryParse(dateTimeFormat, out pResult);     }   } }