如何将时间从 GMT 转换为 PST? [英] How to convert time from GMT to PST?

查看:73
本文介绍了如何将时间从 GMT 转换为 PST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户端应用程序以 GMT 时间发送到我的 SQL 数据库,我需要在 PST 中显示这个时间,我如何在 JAVA 和 javascript 中执行此操作?我需要获取存储在数据库中的 GMT 时间,如 2016-02-05 14:45:05 并以 PST 时间格式显示.

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.

推荐答案

Srikanth Venkatesh 的回答可能会有所帮助:

Srikanth Venkatesh answer may be helpful:

一些例子

在时区之间转换时间

转换时区之间的时间

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);
    }
}

这篇关于如何将时间从 GMT 转换为 PST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆