• 阿里巴巴 ali1688 Date +0800的问题


    package com.example.testredis.controller;
    
            import java.text.DateFormat;
            import java.text.ParseException;
            import java.text.SimpleDateFormat;
            import java.util.Calendar;
            import java.util.Date;
    
    public class TestTime {
        public static void main(String[] args) throws ParseException {
    
            Date nowDate = new Date();
    
    
            DateFormat dateFormat1 = new SimpleDateFormat("yyyyMMddHHmmsszzz");
            System.out.println(dateFormat1.format(nowDate));
    
            //以后遇到+0800的时间也不用怕了,就是普通的时间
            DateFormat dateFormat2 = new SimpleDateFormat("yyyyMMddHHmmssZZZ");
            System.out.println(dateFormat2.format(nowDate));
    
    
            //MM HH 这2个大写是对的
            DateFormat dateFormat3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println(dateFormat3.format(nowDate));
    
            //mm hh 这2个小写是错的
            DateFormat dateFormat4 = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
            System.out.println(dateFormat4.format(nowDate));
    
            //把+0800转换成正规的毫秒
            DateFormat dateFormat5 = new SimpleDateFormat("yyyyMMddHHmmssZZZ");
            String jia800Date = "20191224211649+0800";
            Date date = dateFormat5.parse(jia800Date);
            System.out.println(dateFormat3.format(date));
    
            //转换阿里巴巴的时间,大写SS是毫秒,阿里巴巴的是毫秒
            String ali1688Date = "20200619150904000+0800";
            ali1688Date = ali1688Date.substring(0, ali1688Date.length()-8);
            System.out.println(ali1688Date);
            DateFormat dateFormat6 = new SimpleDateFormat("yyyyMMddHHmmss");
            Date abc = dateFormat6.parse(ali1688Date);
            System.out.println(dateFormat3.format(abc));
        }
    }

    public class TestAliDate {
        public static void main(String[] args) throws ParseException {
            DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSSZ");
            Date wokao = dateFormat.parse("20120801154220368+0800");
    
            DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println(dateFormat1.format(wokao));
    
            //结果为:2012-08-01 15:42:20
    
    
    
        }
    }

  • 相关阅读:
    GDOI模拟赛Round 1
    Codeforces 241B
    Codeforces 325E
    Codeforces 235E
    Codeforces 293B
    Codeforces 263E
    快速傅里叶变换FFT
    后缀自动机
    NOI2011 Day2
    NOI2014 Day2
  • 原文地址:https://www.cnblogs.com/del88/p/12093679.html
Copyright © 2020-2023  润新知