试试这个,替换格式

public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";

public static String getFormattedLocalTimeFromUtc (String utcTimeStamp, String outputFormat) {

String formattedTime = null;

if (!TextUtils.isEmpty (utcTimeStamp)) {

if (utcTimeStamp.contains ("T")) {

String localTime = null;

SimpleDateFormat sdf = new SimpleDateFormat (DATE_FORMAT, Locale.getDefault());

sdf.setTimeZone (TimeZone.getTimeZone ("UTC"));

try {

localTime = sdf.parse (utcTimeStamp).toString();

}

catch (ParseException e) {

e.printStackTrace();

}

DateFormat inputDateFormat = new SimpleDateFormat ("EEE MMM dd HH:mm:ss z yyyy");

inputDateFormat.setTimeZone (TimeZone.getTimeZone ("UTC"));

Date date = null;

try {

date = inputDateFormat.parse (localTime);

}

catch (ParseException e) {

e.printStackTrace();

}

DateFormat outputDateFormat = new SimpleDateFormat (outputFormat);

formattedTime = outputDateFormat.format (date);

}

}

return formattedTime;

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐