gpt4 book ai didi

java - 将给定时间转换为 GMT

转载 作者:行者123 更新时间:2023-11-30 05:00:57 26 4
gpt4 key购买 nike

我曾尝试将给定日期 Mon Jul 04 00:00:00 IST 2011 转换为 GMT,如下所示:2011-07-04 18:10:47 GMT+00: 00 2011 但显示 3/7/11 6:30 PM

这是我的代码:

java.text.SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

java.text.SimpleDateFormat res_format = new SimpleDateFormat("dd/mm/yyyy HH:mm");

java.util.Date date1 = format.parse("2011-07-04 00:00:00");

DateFormat gmtFormat = new SimpleDateFormat();

TimeZone gmtTime = TimeZone.getTimeZone("GMT+00");

gmtFormat.setTimeZone(gmtTime);

System.out.println("Current Time: "+date1);

System.out.println("Time:"+gmtFormat.format(date1));

最佳答案

这对我有用:

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.TimeZone;

public class TZ {

public static void main(String[] args) throws ParseException {
java.text.SimpleDateFormat sourceFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss ZZZ yyyy");

java.text.SimpleDateFormat gmtFormat = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss zzzz");

java.util.Date date1 = sourceFormat.parse("Mon Jul 04 00:00:00 IST 2011");

TimeZone gmtTime = TimeZone.getTimeZone("GMT+00");

gmtFormat.setTimeZone(gmtTime);

System.out.println("Source date: " + date1);

System.out.println("gmt:" + gmtFormat.format(date1));

}
}

关于java - 将给定时间转换为 GMT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6749392/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com