L
laredotornado
Hi,
I'm using Java 6. I'm trying to see if there's a simple way to convert a long varaible (the number of milliseconds since 1970) to a timezone other than GMT. I have another time zone string, MY_TIMEZONE, which could be a timezone string ("GMT-5"), but I'm figuring out this doesn't work ...
long timeInMs = 1368921600000;
final Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone.getTimeZone(MY_TIMEZONE));
cal.setTimeInMillis(timeInMs);
final java.util.Date dateObj = cal.getTime();
System.out.println(dateObj.toString());
Can I parse the time zone string to get the number of hours difference and then just add that? Grateful for any elegant solutions. Thanks, - Dave
I'm using Java 6. I'm trying to see if there's a simple way to convert a long varaible (the number of milliseconds since 1970) to a timezone other than GMT. I have another time zone string, MY_TIMEZONE, which could be a timezone string ("GMT-5"), but I'm figuring out this doesn't work ...
long timeInMs = 1368921600000;
final Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone.getTimeZone(MY_TIMEZONE));
cal.setTimeInMillis(timeInMs);
final java.util.Date dateObj = cal.getTime();
System.out.println(dateObj.toString());
Can I parse the time zone string to get the number of hours difference and then just add that? Grateful for any elegant solutions. Thanks, - Dave