0
我从服务器获取UTC时间,例如 - “2016-01-04T06:27:23.92”。我想将它转换为Jan 4,2016,并在本地Formate中使用。我使用下面的代码,但它不工作 -将UTC时间转换为本地android
Date localTime = new Date(commentDate);
String format = "yyyy/MM/dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(format);
Date gmtTime = new Date(sdf.format(localTime));
Date fromGmt = new Date(gmtTime.getTime() + TimeZone.getDefault().getOffset(localTime.getTime()));
commentDate = commentDate.substring(0, commentDate.lastIndexOf("."));
你正在得到哪个错误? – CAFEBABE
我在“Date localTime = new Date(commentDate);”线。我有时间在字符串合成例如 - “2016-01-04T06:27:23.92” –
http://stackoverflow.com/questions/6049207/convert-utc-to-current-locale-time看到的链接 –