【发布时间】:2015-02-02 20:24:12
【问题描述】:
我在America/Los_Angeles TZ 上,当我尝试在America/Mazatlan TZ 中渲染午夜时,出现以下异常:
Exception in thread "main" java.text.ParseException: Unparseable date: "12:00 AM"
这是我的重现代码:
DateFormat dateFormat = new SimpleDateFormat("h:mm a");
TimeZone timeZone = TimeZone.getTimeZone("America/Mazatlan");
dateFormat.setTimeZone(timeZone);
dateFormat.setLenient(false);
Date parse = dateFormat.parse("12:00 AM");
我知道注释掉 setLenient(false) 将解决问题,我只是不确定为什么这是一个修复,因为同一偏移量中的其他时区,例如 America/Inuvik 不会导致这样的问题。
任何帮助都会很棒。
【问题讨论】:
-
发现了其他几个发生这种情况的 TZ:
America/Hermosillo,Mexico/BajaSur,America/Bahia_Banderas
标签: java date timezone simpledateformat