src/fursvp.helpers/DateTimeExtensions.cs
/// <summary>
/// Converts a DateTime from local time zone to utc time.
/// </summary>
/// <param name="localDateTime">The local datetime.</param>
/// <param name="sourceTimeZoneId">The local time zone from which to convert to utc time.</param>
/// <param name="utcDateTime">The utc datetime result, or the local datetime if conversion was unsuccessful.</param>
/// <returns>A value indicating whether the conversion was successful.</returns>
Converts a DateTime from local time zone to utc time.
Converts a DateTime from local time zone to utc time .
public static bool TryConvertToUtc(this DateTime localDateTime, string sourceTimeZoneId, out DateTime utcDateTime)
        {
            try
            {
                utcDateTime = localDateTime.ToUtc(sourceTimeZoneId);
                return true;
            }
            catch
            {
                utcDateTime = localDateTime;
                return false;
            }
        }
public static bool TryConvertToUtc ( this DateTime localDateTime , string sourceTimeZoneId , out DateTime utcDateTime ) { try { utcDateTime = localDateTime . ToUtc ( sourceTimeZoneId ) ; return true ; } catch { utcDateTime = localDateTime ; return false ; } }
Converts a DateTime from local time zone to utc time.
Converts a DateTime from local time zone to utc time .
A value indicating whether the conversion was successful.
A value indicating whether the conversion was successful .
DateTime
out
sourceTimeZoneId
string
The local time zone from which to convert to utc time.
The local time zone from which to convert to utc time .
localDateTime
The local datetime.
The local datetime .
utcDateTime
The utc datetime result, or the local datetime if conversion was unsuccessful.
The utc datetime result or the local datetime if conversion was unsuccessful .