在我的代码中,我获取当前时间并根据“UTC”时区对其进行格式化,并使用相同的时区对其进行解析,从而将其转换为日期。问题是,我得到的日期,“星期三07月20日13时04分51秒GMT + 05:00 2016”比 其格式化和解析如下对于给定的Locale,Java simpleDateFormat没有正确解析日期?
Calendar calendar = Calendar.getInstance();
Date currentDate = calendar.getTime();
//gives time as "Wed Jul 20 13:04:51 GMT+05:00 2016"
dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
String dateText = dateFormat.format(currentDate);
//This formats dates as following "Wed, 20 Jul 2016 08:04:51 +0000"
现在uptil这里的东西做工精细的代码,与时区GMT + 05的时间:00被转换成标准UTC与GMT + 00:由0000中格式化的日期所示
Date setteledDate = dateFormat.parse(dateText);
现在解析日期如上给出以下日期00。 “Wed Jul 20 13:04:51 GMT + 05:00 2016”。问题是这个日期再次在GMT + 5 和我得到当前日期格式化并解析它的整个目的丢失,因为目的是根据“UTC”(GMT + 00:00)获取当前日期。
请帮忙。
哪些Java版本是ü使用? –
我正在使用Java 7. –
http://stackoverflow.com/questions/21939967/java-simpledateformat-interpret-parse-string-as-utc –