package com.globalroam.util; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class TestForPrictice { public static void main(String[] args) { Calendar cal = Calendar.getInstance(); TimeZone timeZoneOld = cal.getTimeZone(); Date date = new Date(1359641834000L); System.out.println(date); date = changeTimeZone(date, TimeZone.getTimeZone(timeZoneOld.getDisplayName()), TimeZone.getTimeZone("GMT")); } public static Date changeTimeZone(Date date, TimeZone oldZone, TimeZone newZone) { Date dateTmp = null; if (date != null) { int timeOffset = oldZone.getRawOffset() - newZone.getRawOffset(); System.out.println("oldZone.getRawOffset()====>" + oldZone.getRawOffset()); System.out.println("newZone.getRawOffset()====>" + newZone.getRawOffset()); dateTmp = new Date(date.getTime() - timeOffset); } return dateTmp; } }
js: js 获取客户端时区
new Date().getTimezoneOffset();
new Date().getTimezoneOffset();