在Java中将EST转换为EDT或反之亦然 [英] Converting EST to EDT or vice versa in Java

查看:652
本文介绍了在Java中将EST转换为EDT或反之亦然的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉三件事:

Can anybody tell about three things:


  1. 如何从java.util.Date实例检索TimeZone?

  2. 如何知道夏令时是否适用?
    我想我可以通过做timeZone.getDSTSavings知道,但我面临的问题是,即使我使我的系统的日期为2012年2月1日,仍然

  3. 如何将EST时间转换为EDT,反之亦然?


推荐答案


如何从java.util.Date实例检索TimeZone?

How to retrieve TimeZone from java.util.Date instance?

没有这样的东西。 日期 表示自从Unix纪元以来的毫秒数,这是1970年1月1日UTC的午夜。它不与特定的日历系统或时区相关联。换句话说,如果一个朋友和我一起在电话上(零延迟),我点击我的手指,我们都同意日期即使我使用公历,他使用朱利安日历,即使我在伦敦,他在纽约。

There's no such thing. A Date just represents a number of milliseconds since the Unix epoch, which was midnight on January 1st 1970 UTC. It's not associated with a particular calendar system or time zone. To put it another way, if a friend and I are on the phone together (with a zero latency ;) and I click my fingers, we would both agree on the Date at which that click too place - even if I'm using the Gregorian calendar and he's using the Julian calendar, and even if I'm in London and he's in New York. It's the same instant in time.


如何知道夏令时是否适用?知道它通过做timeZone.getDSTSavings,但我面临的问题是,即使我使我的系统的日期为2012年2月1日,仍然我得到的值为正(我猜3600000)

How to know whether Daylight savings is applicable?, I suppose I can know it by doing timeZone.getDSTSavings, but problem I am facing is that even if I make my system's date as Feb 1 2012, still I am getting the value as positive (I guess 3600000)

理想情况下,使用 Joda Time 而不是 java。 util.Date / 日历 / TimeZone ,但在 ,您可以使用 TimeZone.getOffset(long) 查找与UTC的偏移量,或 TimeZone.inDaylightTime(Date) 只是给你一个/无回答。

Ideally, use Joda Time instead of java.util.Date/Calendar/TimeZone, but within TimeZone you can use TimeZone.getOffset(long) to find the offset from UTC, or TimeZone.inDaylightTime(Date) to just give you a yes/no answer.


如何将EST时间转换为EDT或相反?

How to convert EST time to EDT or vice versa?

通常这是一个无效的问题 - 因为在任何一个时间, EST EDT适用。您通常从一个时区转换到另一个时区,EDT和EST不是不同的时区 - 它们是在同一时区内的不同偏移。事实上,你要求这意味着你可能会错误地建模你的数据开始(这是不幸的是很容易做日期/时间值)。请提供更多资讯,我们也许能为您提供更多资讯。

Usually that's an invalid question - because at any one instance in time, either EST or EDT applies. You normally convert from one time zone to another, and "EDT" and "EST" aren't different time zones - they're different offsets within the same time zone. The fact that you're asking for this suggests that you may be modelling your data incorrectly to start with (which is unfortunately easy to do with date/time values). Please give us more information and we may be able to help you more.

这篇关于在Java中将EST转换为EDT或反之亦然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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