- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java util.Calendar;
- public class Test {
- 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.gerInstance();
- 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();
- }
- }
- }
原文地址:https://www.cnblogs.com/cheng2015/p/9151562.html
时间: 2024-10-10 19:43:07