Force Java timezone as GMT/UTC

The OP answered this question to change the default timezone for a single instance of a running JVM, set the user.timezone system property: java -Duser.timezone=GMT … <main-class> If you need to set specific time zones when retrieving Date/Time/Timestamp objects from a database ResultSet, use the second form of the getXXX methods that takes a Calendar … Read more

Difference between UTC and GMT Standard Time in .NET

GMT does not adjust for Daylight saving time (DST). You can hear it from the horse’s mouth on this web site. Add this line of code to see the source of the problem: Console.WriteLine(TimeZoneInfo.FindSystemTimeZoneById(“GMT Standard Time”).SupportsDaylightSavingTime); Output: True. This is not a .NET problem, it is Windows messing up. The registry key that TimeZoneInfo uses … Read more

how to convert php date formats to GMT and vice versa?

Although the gmdate functions are available. If you are using PHP 5.2 or greater, then consider using the DateTime object. Here’s code to switch to GMT $date = new DateTime(); $date->setTimezone(new DateTimeZone(‘GMT’)); and back to the default timezone… $date = new DateTime(‘2011-01-01’, new DateTimeZone(‘GMT’)); $date->setTimezone(new DateTimeZone(date_default_timezone_get())); Using the DateTime object lets your create a datetime, … Read more

PHP daylight saving time detection

As Jimmy points out you can use timezone transitions, but this is not available on PHP <5.3. as dateTimeZone() is PHP>=5.2.2 but getTransitions() with arguments is not! In that case here is a function that can give you timezone data, including whether in DST or not. function timezonez($timezone=”Europe/London”){ $tz = new DateTimeZone($timezone); $transitions = $tz->getTransitions(); … Read more

NSDate – Convert Date to GMT

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.dateFormat = @”yyyy-MM-dd’T’HH:mm”; NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@”GMT”]; [dateFormatter setTimeZone:gmt]; NSString *timeStamp = [dateFormatter stringFromDate:[NSDate date]]; [dateFormatter release];

Get GMT Time in Java

Odds are good you did the right stuff on the back end in getting the date, but there’s nothing to indicate that you didn’t take that GMT time and format it according to your machine’s current locale. final Date currentTime = new Date(); final SimpleDateFormat sdf = new SimpleDateFormat(“EEE, MMM d, yyyy hh:mm:ss a z”); … Read more

SimpleDateFormat parse loses timezone [duplicate]

All I needed was this : SimpleDateFormat sdf = new SimpleDateFormat(“yyyy.MM.dd HH:mm:ss”); sdf.setTimeZone(TimeZone.getTimeZone(“GMT”)); SimpleDateFormat sdfLocal = new SimpleDateFormat(“yyyy.MM.dd HH:mm:ss”); try { String d = sdf.format(new Date()); System.out.println(d); System.out.println(sdfLocal.parse(d)); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } Output : slightly dubious, but I want … Read more