Created
August 10, 2012 05:13
-
-
Save logicbomb/3311232 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class LocalizableDateTime | |
| { | |
| private string _tzid; | |
| private TimeZoneInfo _tzi; | |
| private DateTime _utc; | |
| public string TimeZoneId | |
| { | |
| get { return _tzid; } | |
| private set | |
| { | |
| _tzi = TimeZoneInfo.FindSystemTimeZoneById(value); | |
| _tzid = value; | |
| } | |
| } | |
| public LocalizableDateTime() | |
| : this("GMT Standard Time") | |
| { | |
| } | |
| public LocalizableDateTime(string timezoneId) | |
| { | |
| TimeZoneId = timezoneId; | |
| _utc = DateTime.UtcNow; | |
| } | |
| public LocalizableDateTime(DateTime dt, string timezoneId) | |
| { | |
| TimeZoneId = timezoneId; | |
| _utc = dt.ToUniversalTime(); | |
| } | |
| public override string ToString() | |
| { | |
| return _utc.ToString(CultureInfo.InvariantCulture); | |
| } | |
| public string ToString(string format) | |
| { | |
| return _utc.ToString(format); | |
| } | |
| public string ToLocalString(string format) | |
| { | |
| return ToLocalDateTime().ToString(format); | |
| } | |
| public string ToLocalString() | |
| { | |
| return ToLocalDateTime().ToString(CultureInfo.InvariantCulture); | |
| } | |
| public DateTime ToLocalDateTime() | |
| { | |
| return TimeZoneInfo.ConvertTimeFromUtc(_utc, _tzi); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment