700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 转换为本地时间 java_UTC时间转换为本地时间(JAVA)

转换为本地时间 java_UTC时间转换为本地时间(JAVA)

时间:2021-05-03 15:04:38

相关推荐

转换为本地时间 java_UTC时间转换为本地时间(JAVA)

出处:/s/blog_7d8cef530101ersz.html

JAVA中将UTC时间转换为本地时间的方法,其他的时区转换与此类似。

public static String utc2Local(String utcTime, String utcTimePatten,

String localTimePatten) {

SimpleDateFormat utcFormater = new SimpleDateFormat(utcTimePatten);

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

Date gpsUTCDate = null;

try {

gpsUTCDate = utcFormater.parse(utcTime);

} catch (ParseException e) {

e.printStackTrace();

}

SimpleDateFormat localFormater = new SimpleDateFormat(localTimePatten);

localFormater.setTimeZone(TimeZone.getDefault());

String localTime = localFormater.format(gpsUTCDate.getTime());

return localTime;

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。