Parse a date string into a certain timezone (supporting daylight saving time)

后端 未结 5 2127
一个人的身影
一个人的身影 2020-12-05 23:48

Ok i\'ve been working very hard the last few weeks and i\'ve come across a small problem. I don\'t think my mind is quite up to the task right now :) so i need some tips/hel

5条回答
  •  臣服心动
    2020-12-06 00:17

    This seems to work for me when I need to parse a datetime string from a known timezone into my local one. Haven't tested it in many cases but so far it has worked great for parsing times on a server somewhere in the eu.

    TimeZoneInfo.ConvertTime(DateTime.Parse("2012-05-25 23:17:15", CultureInfo.CreateSpecificCulture("en-EU")),TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"),TimeZoneInfo.Local)
    

提交回复
热议问题