예제 #1
0
        private static String ConstructFullDetailFormatString(DateTime dateTime)
        {
            switch (dateTime.Kind)
            {
            case DateTimeKind.Utc:

                return(FullDetailDateTimeFormatTemplate.ApplyFormat(DateTimeZoneUtcFormat));

            case DateTimeKind.Local:

                return(FullDetailDateTimeFormatTemplate.ApplyFormat(DateTimeZoneLocalFormat));

            case DateTimeKind.Unspecified:

                return(FullDetailDateTimeFormatTemplate.ApplyFormat(String.Empty));

            default:

                throw new ArgumentException($"{dateTime.Kind} is not a supported {nameof(DateTimeKind)}.", nameof(dateTime));
            }
        }
예제 #2
0
        internal static Boolean TryParseFullDetailDateTimeString(String dateTimeString, IFormatProvider formatProvider, out DateTime result)
        {
            var dateTimeStringFormat = dateTimeString.Contains(DateTimeZoneUtcFormat) ? FullDetailDateTimeFormatTemplate.ApplyFormat(DateTimeZoneUtcFormat) : FullDetailDateTimeFormatTemplate.ApplyFormat(DateTimeZoneLocalFormat);

            return(DateTime.TryParseExact(dateTimeString, dateTimeStringFormat, formatProvider, (DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.RoundtripKind), out result));
        }