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)); }