软件版本号规范与命名原则

一、Java中UTC时间转换

Java常用功能开发资料
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();
        }
    }
}
View Code

相关文章:

  • 2021-11-30
  • 2022-02-03
  • 2021-12-18
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-12
  • 2022-12-23
  • 2021-08-11
相关资源
相似解决方案