Java converts Json Date/Date (1487053489965 + 0800)/format and js time format Tue Feb 14 2017 14:06:32 GMT + 0800, json1487053489965

Source: Internet
Author: User

Java converts Json Date/Date (1487053489965 + 0800)/format and js time format Tue Feb 14 2017 14:06:32 GMT + 0800, json1487053489965

/Date (1487053489965 + 0800)/how to convert it to yyyy-MM-dd format in Java

How to convert Tue Feb 14 2017 14:06:32 GMT + 0800 to yyyy-MM-dd format in Java

Not the same as a normal date

    public static void main(String[] args)  
    {        String str="/Date(1487053489965+0800)/";        str=str.replace("/Date(","").replace(")/","");        String time = str.substring(0,str.length()-5);        Date date = new Date(Long.parseLong(time));        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");        System.out.print(format.format(date));    }

 

   public static void main(String[] args) throws ParseException    {      String datdString="Tue Feb 14 2017 14:06:32 GMT+0800";      datdString = datdString.replace("GMT", "").replaceAll("\\(.*\\)", "");      SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd yyyy hh:mm:ss z", Locale.ENGLISH);      Date dateTrans = format.parse(datdString);      System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(dateTrans));    }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.