欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

获取格林威治时间

程序员文章站 2022-05-12 09:04:06
...
package com.timezone;

import java.text.*;
import java.util.*;

/**
 * 获取格林威治时间
 * 
 * @author Administrator
 * 
 */
public class GMTime {
	public static void main(String[] args) {
		final int msInMin = 60000;
		final int minInHr = 60;
		Date date = new Date();
		int Hours, Minutes;
		DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,
				DateFormat.LONG);
		TimeZone zone = dateFormat.getTimeZone();
		System.out.println("IST Time: " + dateFormat.format(date));
		Minutes = zone.getOffset(date.getTime()) / msInMin;
		Hours = Minutes / minInHr;
		System.out.println("GMT Time" + (Hours >= 0 ? "+" : "") + Hours + ":"
				+ Minutes);
		zone = zone.getTimeZone("GMT Time" + (Hours >= 0 ? "+" : "") + Hours
				+ ":" + Minutes);
		dateFormat.setTimeZone(zone);
		System.out.println("GMT: " + dateFormat.format(date));

	}
}
 
相关标签: Java