.net - How do I get the current date and time in the local timezone? -
this question has answer here:
how current date , time in local timezone? system.datetime.now returns current date , time local time zone when program started, wrong thing.
duplicate of sum of:
.net datetime.now returns incorrect time when time zone changed
you use code below if know local time zone you're targetting
datetime timeutc = datetime.utcnow; try { timezoneinfo cstzone = timezoneinfo.findsystemtimezonebyid("central standard time"); datetime csttime = timezoneinfo.converttimefromutc(timeutc, cstzone); console.writeline("the date , time {0} {1}.", csttime, cstzone.isdaylightsavingtime(csttime) ? cstzone.daylightname : cstzone.standardname); } catch (timezonenotfoundexception) { console.writeline("the registry not define central standard time zone."); } catch (invalidtimezoneexception) { console.writeline("registry data on central standard time zone has been corrupted."); }
for more info https://msdn.microsoft.com/en-us/library/bb397769(v=vs.110).aspx
Comments
Post a Comment