java 使用日历从Utc转换为本地时间
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 使用日历从Utc转换为本地时间相关的知识,希望对你有一定的参考价值。
public class DateUtil {
private static final String TAG = "DateHelper";
private static final SimpleDateFormat SERVER_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault());
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("MMM d yyyy, HH:mm:ss", Locale.getDefault());
public static String getFormattedDate(String dateString) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
SimpleDateFormat output = new SimpleDateFormat("dd-MMM-yyyy hh:mm a");
/* SimpleDateFormat output = new SimpleDateFormat("dd-MMM-yyyy");
SimpleDateFormat time = new SimpleDateFormat("hh:mm ");*/
// sdf.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata"));
// sdf.setTimeZone(TimeZone.getDefault());
Date d = sdf.parse(dateString);
String formattedTime = output.format(d);
Date calDate = sdf.parse(dateString);
Calendar calendar = Calendar.getInstance();
calendar.setTime(calDate);
calendar.add(Calendar.HOUR, 5);
calendar.add(Calendar.MINUTE, 30);
Date convertedDate = calendar.getTime();
String convTime = output.format(convertedDate);
return convTime;
}
}
以上是关于java 使用日历从Utc转换为本地时间的主要内容,如果未能解决你的问题,请参考以下文章