Converting string timestamp to date [duplicate]

喜夏-厌秋 提交于 2019-12-10 16:46:54

问题


How do i convert a string time-stamp like "Thu Jun 07 13:01:59 IST 2007" to date format in java?


回答1:


String ds = "Thu Jun 07 13:01:59 IST 2007";
SimpleDateFormat f = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
Date d = f.parse(ds);

As others mentioned, the answer is in the docs.




回答2:


You can use DateFormat:

DateFormat dateFormat = new SimpleDateFormat("E M d HH:mm:ss z yyyy");
Date date = dateFormat.parse("Thu Jun 07 13:01:59 IST 2007");



回答3:


First, create a date and time pattern string as specified in the SimpleDateFormat javadocs and then call parse to convert the string to a Date object.




回答4:


Use SimpleDateFormat. Something like this:

DateFormat fmt = new SimpleDateFormat("EEE MMM d hh:mm:ss Z yyyy");
Date date = fmt.parse(str);


来源:https://stackoverflow.com/questions/10494876/converting-string-timestamp-to-date

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