0

I have a client application sending in GMT time to my SQL DB and i need to display this TIME in PST, How can i do this in JAVA and javascript? I need to get the GMT time which is stored in the db like 2016-02-05 14:45:05 and display it in PST time format.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
Ratan Servegar
  • 375
  • 1
  • 6
  • 21
  • check out the javadocs for Date, DateFormat and TimeZone. Or here are a couple helpful links http://www.mkyong.com/java/java-convert-date-and-time-between-timezone/, http://stackoverflow.com/questions/2891361/how-to-set-time-zone-of-a-java-util-date – obi1 Feb 04 '16 at 21:42
  • 1
    Possible duplicate of [Timezone conversion](http://stackoverflow.com/questions/6567923/timezone-conversion) – Leon Adler Feb 04 '16 at 22:04

1 Answers1

0

Srikanth Venkatesh answer may be helpful:

Some examples

Convert time between timezone

Converting Times Between Time Zones

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class TimeZoneExample {
    public static void main(String[] args) {
        // Create a calendar object and set it time based on the local
        // time zone
        Calendar localTime = Calendar.getInstance();
        localTime.set(Calendar.HOUR, 17);
        localTime.set(Calendar.MINUTE, 15);
        localTime.set(Calendar.SECOND, 20);

        int hour = localTime.get(Calendar.HOUR);
        int minute = localTime.get(Calendar.MINUTE);
        int second = localTime.get(Calendar.SECOND);


        // Print the local time
        System.out.printf("Local time  : %02d:%02d:%02d\n", hour, minute, second);


        // Create a calendar object for representing a Germany time zone. Then we
        // wet the time of the calendar with the value of the local time

        Calendar germanyTime = new GregorianCalendar(TimeZone.getTimeZone("Europe/Berlin"));
        germanyTime.setTimeInMillis(localTime.getTimeInMillis());
        hour = germanyTime.get(Calendar.HOUR);
        minute = germanyTime.get(Calendar.MINUTE);
        second = germanyTime.get(Calendar.SECOND);


        // Print the local time in Germany time zone
        System.out.printf("Germany time: %02d:%02d:%02d\n", hour, minute, second);
    }
}
Community
  • 1
  • 1
Eric S
  • 1,336
  • 15
  • 20
  • the problem is i am not working on my localTime. i am getting the time from SQL which is getting its value from another application which stores the datetime in GMT – Ratan Servegar Feb 06 '16 at 10:57