Advertisement

01.30.2006 at 03:37PM PST, ID: 21716292
[x]
Attachment Details

How to convert local time to GMT time?

Asked by a122178 in Java Programming Language

Tags: gmt, time, convert, local

Hi all,

I want to convert local time to GMT time. However, I implemented the code below:

java.text.SimpleDateFormat format0 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        java.text.SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        java.util.Calendar cal0 = Calendar.getInstance(new SimpleTimeZone(0, "GMT"));
        java.util.Calendar cal1 = Calendar.getInstance(Calendar.getInstance().getTimeZone().getDefault());
        format0.setCalendar(cal0);
        format1.setCalendar(cal1);
        java.util.Date date = format1.parse(format0.format(localDate) + " GMT");
        java.lang.String formatted = format0.format(date);

The result is Mon Jan 30 23:33:17 PST 2006

I don't know why the timezone display PST instead of GMT. Do you have any idea?Start Free Trial
 
Loading Advertisement...
 
[+][-]01.30.2006 at 03:39PM PST, ID: 15829329

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.30.2006 at 03:40PM PST, ID: 15829335

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.30.2006 at 03:43PM PST, ID: 15829356

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.30.2006 at 03:47PM PST, ID: 15829385

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.30.2006 at 05:33PM PST, ID: 15829907

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.30.2006 at 05:36PM PST, ID: 15829922

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Java Programming Language
Tags: gmt, time, convert, local
Sign Up Now!
Solution Provided By: objects
Participating Experts: 2
Solution Grade: A
 
 
[+][-]01.31.2006 at 12:43AM PST, ID: 15831568

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.31.2006 at 09:24AM PST, ID: 15835574

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.31.2006 at 12:55PM PST, ID: 15837563

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32