.net - How do I get the current date and time in the local timezone? -


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

c# event detect daylight saving or manual time change

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

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -