Reputation: 5198
I am doing some XML parsing with SAX Some elements look like this:
<show time="2014-07-05 20:00:00" />
I need to get a Timestamp out of above String. Furthermore I also need to get a java.sql.Date, which of course should ignore the exact time.
I saw that there is a Timestamp.parse(String s)
method available, but it is deprecated.
Therefore I wanted to ask what is the best Method to get a Timestamp out of this string, and a sql Date out of the Timestamp or String.
Thanks in advance
Edit: I by the way still have to use Java 1.7 for this project
Upvotes: 1
Views: 188
Reputation: 336
java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
java.util.Date date = dateFormat.parse("2014-07-05 20:00:00");
java.sql.Timestamp timestamp = new java.sql.Timestamp(date.getTime());
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
Upvotes: 3