【原创】Java中将2019-05-13T06:31:57.790Z这种时间格式转化成本地时间格式yyyy-MM-dd HH:mm:ss

解决方法:(String类型无法直接parse为一个date类型,所以需要先把String字符串,格式化为一个date类型,最后再格式化为你想要的格式)

public String formatDate(String inputDate){
        try{
            DateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
            DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX", Locale.US);
            Date date = inputFormat.parse(inputDate);
            return outputFormat.format(date);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

猜你喜欢

转载自blog.csdn.net/Kevin_Gu6/article/details/90210560