-3
我想獲取上午/下午在gmt時區,但代碼崩潰與此錯誤。我如何在格林威治標準時間/格林尼治標準時間從timepicker中選擇現有/默認時區?獲取上午/下午在gmt時區
代碼:
String selectedHour="15";
String selectedMinute="32";
String am_pm="PM";
SimpleDateFormat sdf = new SimpleDateFormat("HH:MM a", Locale.US);
Date testDate = null;
try {
testDate = sdf.parse(selectedHour+" "+selectedMinute+" "+am_pm);
}catch(Exception ex){
ex.printStackTrace();
}
SimpleDateFormat formatter = new SimpleDateFormat("a");
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
String newFormat = formatter.format(testDate);
System.out.println(".....Date..." + newFormat);
錯誤:
System.err: java.text.ParseException: Unparseable date: "15 32 PM" (at offset 2)
System.err: at java.text.DateFormat.parse(DateFormat.java:579)
感謝。有用 – jason