Friday, June 29, 2012

Converting AD UTC time to DateTime

Convert local time to UTC

TimeZoneInfo.ConvertTimeToUtc(DateTime.Now.AddDays(15)).ToFileTimeUtc()
 
Result
129867569963464980

Convert UTC time to Local time

TimeZoneInfo.ConvertTimeToUtc(DateTime.Now)

Result:
{6/29/2012 4:29:09 PM}
    Date: {6/29/2012 12:00:00 AM}
    Day: 29
    DayOfWeek: Friday
    DayOfYear: 181
    Hour: 16
    Kind: Utc
    Millisecond: 954
    Minute: 29
    Month: 6
    Second: 9
    Ticks: 634765841499549823
    TimeOfDay: {16:29:09.9549823}
    Year: 2012

No comments:

Post a Comment