.NET: Convert to Local Timezone
By admin on Jan 29, 2010 in .NET, Programming
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
Sorry, comments for this entry are closed at this time.