Java examples for java.time:ZoneId
Get TimeZone from ZoneId
import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.ZoneId; import java.util.Date; import java.util.TimeZone; public class Main{ public static Date dateOf(String dateStr) { if (null == dateStr || dateStr.trim().length() == 0) return null; try {/*from w w w . j ava2 s .com*/ SimpleDateFormat format = new SimpleDateFormat( DatePattern.UNTIL_MINUTE.getPattern()); format.setTimeZone(TimeZone.getTimeZone(ZoneId.of("CTT", ZoneId.SHORT_IDS))); return format.parse(dateStr); } catch (ParseException e) { throw new RuntimeException(dateStr + " format is illegal."); } } }