RSS Feed for This PostCurrent Article

.NET: Convert to Local Timezone

You can use the style DateTimeStyles.AssumeLocal to parse the date time string if there is no timezone information contained in the string.

E.g.

   1: DateTime.ParseExact(dateString, DateFormats, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);

If datestring contains no time zone information, the DateTime..::.Parse(String, IFormatProvider, DateTimeStyles) method returns a DateTime value whose Kind property is DateTimeKind..::.Unspecified unless a styles flag indicates otherwise.

If datestring includes time zone or time zone offset information, the DateTime..::.Parse(String, IFormatProvider, DateTimeStyles) method performs any necessary time conversion and returns one of the following:

  • A DateTime value whose date and time reflect the local time and whose Kind property is DateTimeKind..::.Local.
  • Or, if styles includes the AdjustToUniversal flag, a DateTime value whose date and time reflect UTC and whose Kind property is DateTimeKind..::.Utc


Trackback URL


Sorry, comments for this entry are closed at this time.