Getting the Date format in Java [duplicate]

前提是你 提交于 2019-12-12 02:23:31

问题


I am have this String from a Date object: Mon Mar 25 00:00:00 IST 2013

What is the String representation of the date format?


回答1:


The code below should work fine.

public static void main(String[] args) throws Exception {
    String target = "Mon Mar 25 00:00:00 IST 2013";
    DateFormat df = new SimpleDateFormat("EEE MMM dd kk:mm:ss z yyyy", Locale.ENGLISH);
    Date result =  df.parse(target);  
    System.out.println(result);
}

Read the javadoc for the valid patterns.




回答2:


String yourDate= "Mon Mar 25 00:00:00 IST 2013" ;
DateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
Date jDate = new Date(df.parse(yourDate).getTime());
System.out.println(jDate);


来源:https://stackoverflow.com/questions/15546494/getting-the-date-format-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!