标签:spl bst end pen form local 时间转换 sim get
一、Java中UTC时间转换
import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class UTCTimeConverter { public static void main(String[] args) { // SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd‘T‘HH:mm:ss.SSSXXX"); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd‘T‘HH:mm:ss"); SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd"); try { String utcDateStr = "2018-01-22T09:12:43.083Z"; Date date = sdf1.parse(utcDateStr.substring(0, 19));// 拿到Date对象 Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.HOUR_OF_DAY, 8); // 加8小时 String localDateStr = sdf2.format(cal.getTime()); String str = sdf2.format(localDateStr);// 输出格式:2017-01-22 09:28:33 System.out.println(str); } catch (Exception e) { e.printStackTrace(); } } }
标签:spl bst end pen form local 时间转换 sim get
原文地址:https://www.cnblogs.com/cheng2015/p/12746169.html