Mehul Dudhat
Mehul Dudhat

Reputation: 431

SE Asia Standard Time zone showing Unparseable date exception during parsing date format

I try with different timezone in date, that all working fine, but SE Asia Standard Time is not parsing with the full date showing Unparseable date exception.

String date="Sun Jan 18 2015 22:11:44 GMT+0700 (SE Asia Standard Time)";
        SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss 'GMT'Z (zzzz)");
        try{
            System.out.println(new Timestamp(sdf.parse(date).getTime()));
        }catch(Exception e){
            e.printStackTrace();
        }

Upvotes: 2

Views: 1151

Answers (2)

DirkNM
DirkNM

Reputation: 2664

Looks like in Java this timezone is called "Indochina Time"

I think the name of the timezone is not nessessary to parse the correct date because you have also the time offset in your string. So removing the timezone name from the string should do it.

public static void main(String[] args) {
    String date = "Sun Jan 18 2015 22:11:44 GMT+0700 (SE Asia Standard Time)";

    date = date.substring(0, date.indexOf("("));
    SimpleDateFormat sdf = new SimpleDateFormat(
            "EEE MMM dd yyyy HH:mm:ss 'GMT'Z", Locale.ENGLISH);
    try {
        System.out.println(new Timestamp(sdf.parse(date).getTime()));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Upvotes: 1

Yosef Weiner
Yosef Weiner

Reputation: 5751

"SE Asia Standard Time" is not one of the supported timezones. For GMT+7, here are the available timezones:

public static void main(String[] args) {
    Arrays.asList(TimeZone.getAvailableIDs()).stream()
            .map(TimeZone::getTimeZone)
            .filter(zone -> zone.getRawOffset() == 7 * 60 * 60 * 1000)
            .forEach(zone -> System.out.printf("%-20s  %s\n", zone.getID(), zone.getDisplayName()));
}
Antarctica/Davis      Davis Time
Asia/Bangkok          Indochina Time
Asia/Ho_Chi_Minh      Indochina Time
Asia/Hovd             Hovd Time
Asia/Jakarta          West Indonesia Time
Asia/Krasnoyarsk      Krasnoyarsk Time
Asia/Novokuznetsk     Krasnoyarsk Time
Asia/Phnom_Penh       Indochina Time
Asia/Pontianak        West Indonesia Time
Asia/Saigon           Indochina Time
Asia/Vientiane        Indochina Time
Etc/GMT-7             GMT+07:00
Indian/Christmas      Christmas Island Time
VST                   Indochina Time

Upvotes: 1

Related Questions