[英]convert string into java.util.date format in java
am having a string like this. 我有这样的字符串。
Thu Oct 07 11:31:50 IST 2010
I want to convert this into its exact date time format to store it in SQL. 我想将其转换为确切的日期时间格式,以将其存储在SQL中。
Am familiar with so many string to date conversions like the following. 我熟悉如此多的字符串到日期转换,如下所示。
String dateString = "2001/03/09";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/mm/dd");
Date convertedDate = dateFormat.parse(dateString);
But i need to convert a string like Thu Oct 07 11:31:50 IST 2010
into its Date format with timestamp. 但我需要将字符串像Thu Oct 07 11:31:50 IST 2010
转换为带时间戳的日期格式。
Can anyone explain the proper way of converting this into its java.util.Date format.? 任何人都可以解释将其转换为java.util.Date格式的正确方法。
Try this: 试试这个:
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
For future reference read up on the SimpleDateFormat class: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html 有关SimpleDateFormat类的未来参考,请阅读: http : //docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
Can't you do like below 你不能在下面做
String str = "Thu Oct 07 11:31:50 IST 2010";
SimpleDateFormat sdf = new SimpleDateFormat("E MMM dd hh:mm:ss 'IST' yyyy");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd");
System.out.println(sdf2.format(sdf.parse(str)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.