---
title: "根据浏览器的时区显示服务器时间（utc）"
author: "youjin"
date: "2014-10-24T16:29:58Z"
tags: []
categories: ["Web前端"]
slug: "utc"
draft: false
lastmod: "2014-10-24T16:29:58Z"
id: 2147627
url: "https://youjin.iteye.com/blog/2147627"
---

1.js获取客户端系统的时区
   var tzo=(new Date().getTimezoneOffset()/60)*(-1); //北京  8
2.把tzo参数传递到服务端，设置返回时间为客户端时区的时间：
   public static void main(String [] arg)
{
TimeZone time = TimeZone.getTimeZone("GMT+8"); //设置为东八区
time = TimeZone.getDefault();// 这个是国际化所用的
System.out.println(time);
TimeZone.setDefault(time);// 设置时区
Calendar calendar = Calendar.getInstance();// 获取实例
DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//构造格式化模板
Date date = calendar.getTime(); //获取Date对象
String str = new String();
str = format1.format(date);//对象进行格式化，获取字符串格式的输出
System.out.println(str);
}
