获取格林威治时间

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)