相关疑难解决方法(0)

确定指定日期的Java夏令时(DST)是否处于活动状态

我有一个Java类,它接收位置的纬度/经度,并在夏令时开启和关闭时返回GMT偏移.我正在寻找一种简单的方法来确定Java当前日期是否为夏令时,因此我可以应用正确的偏移量.目前我只对美国时区执行此计算,但最终我还希望将其扩展到全球时区.

java datetimeoffset dst

59
推荐指数
3
解决办法
9万
查看次数

EST与America/New_York时区的差异

有人可以告诉我,以下两个陈述之间的区别是什么:

TimeZone.getTimeZone("America/New_York")
Run Code Online (Sandbox Code Playgroud)

TimeZone.getTimeZone("EST")
Run Code Online (Sandbox Code Playgroud)

换句话说,为什么EST与America/New_York不同.同样在我的应用程序中,要获得美国当前时区,我应该使用America/New_York还是EST.

java timezone calendar

48
推荐指数
3
解决办法
5万
查看次数

为什么日历使用正确的时区返回错误的小时?


返回的时间和日期是正确的,除了小时,它比它应该小1小时.

我似乎设置了获得正确时间和日期所需的一切:

 - I'm using Calendar.getInstance(), instead of new Date()
 - I'm setting the timezone of the Calendar instance with Timezone.getTimeZone
 - I'm using DateFormat and SimpleDateFormat to format the output
Run Code Online (Sandbox Code Playgroud)


我的时区是Eastern Standard Time,又名UTC/GMT-5:00.这些行都没有任何影响:

 - cal.setTimeZone(TimeZone.getTimeZone(cal.getTimeZone().getDisplayName()));
 - cal.setTimeZone(TimeZone.getTimeZone("EST"));
 - cal.setTimeZone(TimeZone.getTimeZone("UTC"));
 - cal.setTimeZone(TimeZone.getTimeZone("GMT"));
 - cal.setTimeZone(TimeZone.getTimeZone("GMT-5:00"));
Run Code Online (Sandbox Code Playgroud)

...但是这些选项中的每一个都设定了我想要的时区.


这是我的尝试,我错误地向Calendar实例添加了1小时:

PrintWriter output = null;

try {
  output = new PrintWriter(
   new BufferedWriter(new FileWriter("output.txt", true)));

  DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:ms MM/dd/yyyy");
  Calendar cal = Calendar.getInstance();

  // …
Run Code Online (Sandbox Code Playgroud)

java timezone datetime calendar

8
推荐指数
1
解决办法
1万
查看次数

使用 Java 8 时间将时间从一个时区转换为另一个时区

我正在尝试使用 java 8将 Date 转换为GMT +5:30to 。ESTZonedDateTime

String inputDate = "2015/04/30 13:00";
DateTimeFormatter sourceFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm", Locale.US);
LocalDateTime local = LocalDateTime.parse(inputDate, sourceFormatter);
// local : 2015-04-30T13:00
//Combining this local date-time with a time-zone to create a ZonedDateTime. 
ZonedDateTime zoned = local.atZone(TimeZone.getTimeZone("GMT+5:30").toZoneId());
// zoned : 2015-04-30T13:00+05:30[GMT+05:30]
ZonedDateTime zonedUS = zoned.withZoneSameInstant(TimeZone.getTimeZone("GMT-5:00").toZoneId());
// zonedUS : 2015-04-30T02:30-05:00[GMT-05:00]
Run Code Online (Sandbox Code Playgroud)

我期待3:30 AM EST,但是我所得到的是2:30 AM EST作为1 PM IST= 3:30AM EST。我错过了什么?

java timezone

7
推荐指数
1
解决办法
6786
查看次数

将EDT时区转换为GMT在java中无法正常工作

我正在使用此代码来解析此日期.它必须显示新的日期为"2012-06-20 03:09:38",因为EDT是-4GMT,我当前的位置是GMT + 5.但它没有显示它现在显示它是

private static void convertEDT_TO_GMT() {
    try {
        String s = "2012-06-20 18:09:38";
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        df.setTimeZone(TimeZone.getTimeZone("EDT"));
        Date timestamp = null;

        timestamp = df.parse(s);
        df.setTimeZone(TimeZone.getTimeZone("GMT+05:00"));
        System.out.println("Old = " + s);
        String parsed = df.format(timestamp);
        System.out.println("New = " + parsed);

    } catch (Exception e) {
        e.printStackTrace();
    }
    }
Run Code Online (Sandbox Code Playgroud)

它表明

老= 2012-06-20 18:09:38

新= 2012-06-20 23:09:38

java timezone

3
推荐指数
1
解决办法
8906
查看次数

标签 统计

java ×5

timezone ×4

calendar ×2

datetime ×1

datetimeoffset ×1

dst ×1