我试图从星期五08 09:33:00格林尼治标准时间 05:30 2017至" 08-09-2017 09:33" Android中的时间此08-09-2017 04:03这里的时间无法正确。。。
字符串dateTime ="星期五08 09:33:00 GMT 05:30 2017"
dateformat inputformat = new simpledateformat( " E MMM DD HH:MM:SS'GMT'Z Yyyy",locale.English);
Date dateone = null;
try {
dateone = inputFormat.parse(dateTime);
DateFormat outputFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm",
Locale.ENGLISH);
outputFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
dateTimeForUpdate = outputFormat.format(dateone);
} catch (ParseException e) {
e.printStackTrace();
}
您将时区设置为UTC
,而04:03
是该时区的正确时间。如果您想在( 05:30)时区获取时间,请将其设置为DateFormat
对象。
尝试这样的尝试:
outputFormat.setTimeZone(TimeZone.getTimeZone("GMT+5:30"));
dateTimeForUpdate = outputFormat.format(dateone);
System.out.println(dateTimeForUpdate);