问题
I try to parse string (russian locale) "01 августа 2014, пятница. 20:00 МСК" to java.util.Date. I try this code:
String dateString = "01 августа 2014, пятница. 20:00 МСК"
Locale rusLocale = new Locale.Builder().setLanguage("ru").setScript("Cyrl").build();
String pattern = "dd MMMM yyyy, EEEE. HH:mm z"
Date date = SimpleDateFormat(pattern, rusLocale).parse(dateString)
With month and weekday this code work fine, but when I try to parse string with timezone name МСК I get java.text.ParseException: Unparseable date. When I change MCK to MSK "01 августа 2014, пятница. 20:00 MSK" code also work fine. So we can parse strings month and weekday, but can't do it with timezone or "MCK" is just not valid?
回答1:
Try this code. I think it is something relevant with your code.
String dateString = "17 октябрь 2014, пятница. 20:00";
Locale rusLocale = new Locale.Builder().setLanguage("ru").setScript("Cyrl").build();
String pattern = "dd MMMM yyyy, EEEE. HH:mm";
try {
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, rusLocale);
dateFormat.setTimeZone(TimeZone.getTimeZone("МСК"));
Date date = dateFormat.parse(dateString);
} catch (ParseException e) {
...
来源:https://stackoverflow.com/questions/26083062/parsing-string-to-date-with-timezone-in-national-format