我在应用程序中显示日期时遇到问题.
我得到时间戳为:
2017-08-02T06:05:30.000Z
但就此而言,实际时间是:
2017:08:02 11:35 AM
但在使用我的代码转换后,它将时间显示为:
上午6:00
如何显示当前时间?
我的代码如下:
private static SimpleDateFormat timestampformat =
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.mmm'Z'");
private static SimpleDateFormat sdftimeformat = new SimpleDateFormat("HH:mm a");
private static SimpleDateFormat getSdftimeformat() {
return sdftimeformat;
}
public static String timeStampConvertToTime(String time) {
Date date1 = null;
try {
date1 = timestampformat.parse(time);
} catch (ParseException e) {
e.printStackTrace();
}
String formattedTime = getSdftimeformat().format(date1);
return formattedTime;
}
Run Code Online (Sandbox Code Playgroud)