在java中将字符串转换为java.util.date格式 [英] convert string into java.util.date format in java
问题描述
我有一个这样的字符串。
am having a string like this.
Thu Oct 07 11:31:50 IST 2010
我想将其转换为确切的日期时间格式,以将其存储在SQL中。
I want to convert this into its exact date time format to store it in 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);
但是,我需要转换一个字符串,如 Thu Oct 07 11:31: 50 IST 2010
到其日期格式与时间戳。
But i need to convert a string like Thu Oct 07 11:31:50 IST 2010
into its Date format with timestamp.
任何人都可以解释将其转换为其java.util的正确方法。日期格式?
Can anyone explain the proper way of converting this into its java.util.Date format.?
推荐答案
尝试这样:
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
有关SimpleDateFormat类的未来引用,请阅读:
http://docs.oracle.com/javase/7/docs/api/java /text/SimpleDateFormat.html
For future reference read up on the SimpleDateFormat class: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
这篇关于在java中将字符串转换为java.util.date格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!