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

Get Daylight Saving Transition Dates For Time Zones in Java

Joda Time (as ever) makes this really easy due to the DateTimeZone.nextTransition method. For example: import org.joda.time.*; import org.joda.time.format.*; public class Test { public static void main(String[] args) { DateTimeZone zone = DateTimeZone.forID(“Europe/London”); DateTimeFormatter format = DateTimeFormat.mediumDateTime(); long current = System.currentTimeMillis(); for (int i=0; i < 100; i++) { long next = zone.nextTransition(current); if (current … Read more

Does ConvertTimeFromUtc() and ToUniversalTime() handle DST?

Yes. ConvertTimeFromUtc will automatically handle daylight saving time adjustments, as long as the time zone that you are targeting uses daylight saving time. From the MSDN documentation: When performing the conversion, the ConvertTimeFromUtc method applies any adjustment rules in effect in the destinationTimeZone time zone. You should not try to add an additional hour in … Read more

How to tell if a timezone observes daylight saving at any time of the year?

I’ve found a method which works using PHP’s DateTimezone class (PHP 5.2+) function timezoneDoesDST($tzId) { $tz = new DateTimeZone($tzId); $trans = $tz->getTransitions(); return ((count($trans) && $trans[count($trans) – 1][‘ts’] > time())); } or, if you’re running PHP 5.3+ function timezoneDoesDST($tzId) { $tz = new DateTimeZone($tzId); return count($tz->getTransitions(time())) > 0; } The getTransitions() function gives you information … 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