ISO8601时间字符串转时间戳 2019-10-24T22:12:00.000+08:00

public static Long toTimeStamp(String time,String format){
        //yyyy-MM-dd'T'HH:mm:ss.sss
        //2019-10-24T22:12:00.000+08:00
        Long timeStamp = null;
        try{
            SimpleDateFormat dateFormat = new SimpleDateFormat(format);
            Date date = dateFormat.parse(time);
            timeStamp =date.getTime();
        }catch(Exception e){
            timeStamp = null;
        }
        return timeStamp;
    }    

format不需要和传入的time格式完全一样,只要前面一样就可以

这样就可以把 2019-10-24T22:12:00.000+08:00 转化为 1571926320000 

 

posted @ 2019-10-24 22:12  heamin-java  阅读(2073)  评论(0编辑  收藏  举报