如何从格式为
2013-08-15T13:00:00-07:00
的日期时间字符串中获取时区?2013-08-15T13:00:00-07:00
的日期时间字符串中获取时区?String input = "2013-08-15T13:00:00-07:00";
ZonedDateTime zDateTime = ZonedDateTime.parse(input, DateTimeFormatter.ISO_ZONED_DATE_TIME);
ZoneId zone = zDateTime.getZone();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
Date withTZ = sdf.parse("2013-08-15T13:00:00-07:00");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date noTZ = sdf2.parse("2013-08-15T13:00:00-07:00");
TimeZone tmzo = TimeZone.getTimeZone("GMT"+offset);
System.out.println(tmzo.getID());
String input = "2013-08-15T13:00:00-07:00";
Matcher m = Pattern.compile("(?:[+-]\\d{2}:\\d{2}|Z)$").matcher(input);
if (m.find())
System.out.println("Time zone: " + m.group());
else
System.out.println("No time zone found");