Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 1.8 refuses to parse dates with US/Aleutian (HAST) time zone?

I am trying to parse a US/Aleutian timestamp. This has worked in the past, and I couldn't find out why it is no longer working. I'm running Java 1.8 update 72.

The code is as follows:

    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
        sdf.setTimeZone(TimeZone.getTimeZone("US/Aleutian"));

        // the following line throws an parsing exception
        Date d = sdf.parse("1969-12-31T13:00:00HAST");
        System.out.println(sdf.format(d));

    } catch (Exception e) {
        e.printStackTrace();
    }

... the Date d = sdf.parse("1969-12-31T13:00:00HAST"); line throws an exception, but I cannot find out what's wrong with it:

java.text.ParseException: Unparseable date: "1969-12-31T13:00:00HAST"
    at java.text.DateFormat.parse(Unknown Source)

I am certain that this has worked in the past. I researched the HAST time zone, and it is valid. I'm not sure why this isn't working for me.

Can anyone find out what's going on? If this works for you, can you please list your java version so we can find out if/when this got broken?

Thanks!

like image 992
Edy Bourne Avatar asked Dec 03 '25 15:12

Edy Bourne


1 Answers

Found the answer.

According to this, that abbreviation was removed in Java 6 update 101:

"The abbreviations for Hawaii-Aleutian standard and daylight times have been changed from HAST/HADT to HST/HDT, as per US Government Printing Office style. This affects only America/Adak since 1983, as America/Honolulu was already using the new style."

So I'll go ahead and use HST instead.

Thanks for the input everyone!

like image 139
Edy Bourne Avatar answered Dec 06 '25 04:12

Edy Bourne