当地时间与 EST 时间换算 [英] Local time to EST time Conversion

查看:59
本文介绍了当地时间与 EST 时间换算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android 本地时间到 EST 时间的转换

Android Local time to EST time Conversion

代码:

SimpleDateFormat serverDateFormat=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
serverDateFormat.setTimeZone(TimeZone.getTimeZone("EST"));
Calendar calender= Calendar.getInstance(Locale.getDefault());
String  time=serverDateFormat.format(calender.getTime());

但我时间错了.与正确时间相差一小时.例如:当地时间:2015 年 7 月 7 日星期二 17:30:00 GMT+05:30形成时间:2015/07/07 07:00:00正确时间:2015/07/07 08:00:00

but i getting wrong time. one hour difference from right time. for eg : local time : Tue Jul 07 17:30:00 GMT+05:30 2015 formated time : 2015/07/07 07:00:00 right time : 2015/07/07 08:00:00

推荐答案

您的问题是使用了代表东部标准时间"的标识符EST".顾名思义,它不使用夏令时规则.证明:

Your problem is using the identifier "EST" which stands for "Eastern Standard Time". As the name suggests it does not use daylight saving rules. Proof:

TimeZone tz = TimeZone.getTimeZone("EST");
long offset = tz.getOffset(System.currentTimeMillis()) / (1000 * 3600);
System.out.println(tz.getID() + ":" + tz.useDaylightTime() + "/" + offset);
// output: EST:false/-5

改用时区 IDAmerica/New_York":

Use the timezone id "America/New_York" instead:

tz = TimeZone.getTimeZone("America/New_York");
offset = tz.getOffset(System.currentTimeMillis()) / (1000 * 3600);
System.out.println(tz.getID() + ":" + tz.useDaylightTime() + "/" + offset);
// output: America/New_York:true/-4

然后您将在 7 月观察夏令时,偏移差为 (+05:30) - (-04:00) = +09:30,导致预计当地时间为上午 8 点.

Then you will observe daylight saving time in July making an offset difference of (+05:30) - (-04:00) = +09:30 resulting in the expected local time 8 AM.

这篇关于当地时间与 EST 时间换算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆