---
title: "获取格林威治时间"
author: "andyaohui"
date: "2009-11-16T15:22:03Z"
tags: ["Java"]
slug: "untitled"
draft: false
lastmod: "2009-11-16T15:22:03Z"
id: 518218
url: "https://andyaohui.iteye.com/blog/518218"
---

```
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));

	}
}
```