Java ZoneId getTimezone(String tzid)

Here you can find the source of getTimezone(String tzid)

Description

Get the ZoneId of a String that could be a valid tzid.

License

Open Source License

Parameter

Parameter Description
tzid The timezone identifier

Return

The ZoneId of the parsed timezone identifier, or "America/New_York" if tzid is invalid.

Declaration

public static ZoneId getTimezone(String tzid) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.time.ZoneId;

public class Main {
    /**/* ww  w .  j  a v a 2s . co m*/
     * Get the ZoneId of a String that could be a valid tzid.
     *
     * @param tzid  The timezone identifier
     * @return  The ZoneId of the parsed timezone identifier, or "America/New_York" if tzid is invalid.
     */
    public static ZoneId getTimezone(String tzid) {
        try {
            return ZoneId.of(tzid);
        } catch (Exception e) {
            return ZoneId.of("America/New_York");
        }
    }
}

Related

  1. fromEpochMilliseconds(final Long fromEpoch)
  2. getDefaultTimeZone()
  3. getDefaultZoneId()
  4. getDefaultZoneId()
  5. getRequestTimeZone(String timestamp)
  6. getTimeZoneId(final TimeZone tz)
  7. getZoneDateTime(Date d, String tzId)
  8. getZoneId()
  9. getZoneId(String tzId)