将当前 EST 与美国东部标准时间下午 2 点进行比较?如何? [英] Compare the current EST to 2PM EST? How?

查看:46
本文介绍了将当前 EST 与美国东部标准时间下午 2 点进行比较?如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这段代码可以返回当前的 EST

So I have this piece of code that would return the current EST

Date easternTime = new Date();
DateFormat format = new SimpleDateFormat("h:mm a");
format.setTimeZone(TimeZone.getTimeZone("EST"));
return format.format(easternTime);

假设它返回 x = 12:15PM

我想将 x 与美国东部标准时间下午 3:00 进行比较,以查看 x 是在美国东部标准时间下午 3:00 之前还是之后,和/或在美国东部时间下午 3:00 - 6:00 之间是 x.有没有办法做到这一点.

I want to compare x to 3:00PM EST to see if x before or after 3:00PM EST, and/or is x between 3:00PM - 6:00PM EST. Is there a way to do this.

我们不必使用 java.util.date.我也用 calendar 解决

We dont have to use java.util.date. I take solution with calendar as well

推荐答案

肯定会在 Joda Time 代替.如果您真的想使用内置 API 来做到这一点,您需要使用 Calendar 来查找特定时区中的本地时间 - 但 Joda 会做得很多更简单.

I would definitely do this in Joda Time instead. If you really want to do this with the built-in API, you need to use Calendar to find the local time in a particular time zone - but Joda would make it much simpler.

您将使用 DateTime 位于特定时区,并可能从中获取 LocalTime 以与您硬编码(或从中读取)的某些 LocalTime 进行比较配置文件等).

You'd use a DateTime which is in a specific time zone, and possibly take the LocalTime from that to compare with some LocalTimes you've hard-coded (or read from a configuration file etc).

这篇关于将当前 EST 与美国东部标准时间下午 2 点进行比较?如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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