I want to convert this GMT time stamp to GMT+13:
2011-10-06 03:35:05
I have tried about 100 different combinations of DateFormat, TimeZone, Date, GregorianCalendar etc. to try to do this VERY basic task.
This code does what I want for the CURRENT TIME:
Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
DateFormat formatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss z");
formatter.setTimeZone(TimeZone.getTimeZone("GMT+13"));
String newZealandTime = formatter.format(calendar.getTime());
But what I want is to set the time rather than using the current time.
I found that anytime I try to set the time like this:
calendar.setTime(new Date(1317816735000L));
the local machine's TimeZone is used. Why is that? I know that when "new Date()" returns UTC+0 time so why when you set the Time in milliseconds does it no longer assume the time is in UTC?
Is it possible to:
- Set the time on an object (Calendar/Date/TimeStamp)
- (Possibly) Set the TimeZone of the initial time stamp (calendar.setTimeZone(...))
- Format the time stamp with a new TimeZone (formatter.setTimeZone(...)))
- Return a string with new time zone time. (formatter.format(calendar.getTime()))
0 answers
Hot tools Tags
Hot Questions
Popular tool
vc9-vc14 (32+64 bit) runtime library collection (link below)
Download the collection of runtime libraries required for phpStudy installation
VC9 32-bit
VC9 32-bit phpstudy integrated installation environment runtime library
PHP programmer toolbox full version
Programmer Toolbox v1.0 PHP Integrated Environment
VC11 32-bit
VC11 32-bit phpstudy integrated installation environment runtime library
SublimeText3 Chinese version
Chinese version, very easy to use
Hot Topics
20524
7
13634
4






