JAVA 获取格林威治时间(GMT)

时间:2024-05-23 17:48:58

记录下获取GMT时间的方法:
//格式可根据需要自定义,如yyyy-MM-dd HH:mm:ss 等等
SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
Calendar calendar = Calendar.getInstance();
sdf.setTimeZone(TimeZone.getTimeZone("GMT")); // 设置时区为GMT
String dateStr = sdf.format(calendar.getTime());
System.out.println("格林威治时间为:" + dateStr);
输出结果为:格林威治时间为:Wed, 3 Jun 2020 07:03:57 GMT

 

运行j截图

JAVA 获取格林威治时间(GMT)