c# - How to convert day (day of the week) and time as string to different Timezones in .Net -


i have convert various amount of strings in local timezone (.tolocaltime()) unlike normal datetime string strings contain day , time (they supposed in utc) so:

sunday:17:00  friday:16:50 monday:20:50 thursday:07:00 

i looking clever way "convert" strings local timezone since can not datetime out of have manually avoid. (also not split string... )

you cannot handle timezoneoffset correctly without knowing exact date, because offset may change 1 day other (dst vs non-dst).

getting correct time easy part (if have correct date), use appropriate constructor of datetime.

datetime(int year, int month, int day, int hour, int minute, int second, system.datetimekind kind) 

and specify kind system.datetimekind.utc. have timestamp utc time , can use tolocaltime() correct time in local timezone.

the hard part seems me, getting correct date out of data. sunday meant, next 1 (ie 2016-07-10) or last 1 (2016-07-03)? important dates near switch of dst because may result in different timestamps.

also aware 'sunday:23:00' utc may become 'monday:01:00' (and vice versa) timezones! you'll have calculation of date based on utc , not local time. instance, if in local time it's monday 2016-07-04 01:00, sunday 2016-07-03 23:00 in utc interpreting timestamp sunday:17:00 using local time (and wanting next sunday) result in 2016-07-10 19:00 instead of 2016-07-03 19:00.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -