Converting Between Local Times and GMT/UTC in C/C++

You’re supposed to use combinations of gmtime/localtime and timegm/mktime. That should give you the orthogonal tools to do conversions between struct tm and time_t. For UTC/GMT: time_t t; struct tm tm; struct tm * tmp; … t = timegm(&tm); … tmp = gmtime(t); For localtime: t = mktime(&tm); … tmp = localtime(t); All tzset() does … Read more

.NET DateTime.Now returns incorrect time when time zone is changed

Yes, the current time zone is cached. For a good reason, it avoids trouble with broken code that uses DateTime.Now to implement elapsed time measurement. Such code tends to suffer a heart-attack when the time suddenly changes by an hour or more. You will have to call System.Globalization.CultureInfo.ClearCachedData() to reset the cached value. The next … Read more

.NET DateTime.Now returns incorrect time when time zone is changed

Yes, the current time zone is cached. For a good reason, it avoids trouble with broken code that uses DateTime.Now to implement elapsed time measurement. Such code tends to suffer a heart-attack when the time suddenly changes by an hour or more. You will have to call System.Globalization.CultureInfo.ClearCachedData() to reset the cached value. The next … Read more

Timezone conversion in a Google spreadsheet

Short answer There is no built-in function but you could build a custom function. Example /** * Converts a datetime string to a datetime string in a targe timezone. * *@param {“October 29, 2016 1:00 PM CDT”} datetimeString Date, time and timezone. *@param {“Timezone”} timeZone Target timezone *@param {“YYYY-MM-dd hh:mm a z”} Datetime format *@customfunction … Read more

Check if daylight savings is in effect?

Think you need convert this xml to DateTime and then use TimeZoneInfo class. If Denmark your local time: DateTime thisTime = DateTime.Now; bool isDaylight = TimeZoneInfo.Local.IsDaylightSavingTime(thisTime); Else you need to get Denmark TimeZone: DateTime thisTime = DateTime.Now; // get Denmark Standard Time zone – not sure about that TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById(“Denmark Standard Time”); bool … Read more

Convert UTC DateTime to another Time Zone

The best way to do this is simply to use TimeZoneInfo.ConvertTimeFromUtc. // you said you had these already DateTime utc = new DateTime(2014, 6, 4, 12, 34, 0); TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(“Pacific Standard Time”); // it’s a simple one-liner DateTime pacific = TimeZoneInfo.ConvertTimeFromUtc(utc, tzi); The only catch is that the incoming DateTime value may not … Read more

Daylight Savings and Cron

The answer would be dependent on the variant/extension of cron you are using. Some variants do not handle the Daylight Saving Time, leading to missing jobs and twice run of the job. If you are using the Paul Vixie cron, then it does handle the DST changes. As per the cron man page: cron checks … Read more

Python daylight savings time

You can use time.localtime and look at the tm_isdst flag in the return value. >>> import time >>> time.localtime() (2010, 5, 21, 21, 48, 51, 4, 141, 0) >>> _.tm_isdst 0 Using time.localtime(), you can ask the same question for any arbitrary time to see whether DST would be (or was) in effect for your … Read more