//获取格林威治标准时间
public void getGMTTime() {
//mothed 2
TimeZone gmtTime = TimeZone.getTimeZone("GMT");
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
format.setTimeZone(gmtTime);
System.out.println("GMT Time: " + format.format(date));
//method 2
Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeZone(gmtTime);
//System.out.println(calendar1.getTime()); //时区无效
//System.out.println(calendar1.getTimeInMillis()); //时区无效
System.out.println("GMT hour = " + calendar1.get(Calendar.HOUR));
}
网友评论