2

i need to format this String date Tue Sep 23 14:36:59 PKT 2014 to java sql date but i need both date and time, i tried this

String st = "Tue Sep 23 14:36:59 PKT 2014"; new java.sql.Date(new SimpleDateFormat("EEE MMM dd hh:mm:ss zzz yyyy").parse(st).getTime()) 

but it returns only date part and time part is 00:00 can any one help me to sort this issue out.

Regards and thanks in advance.

3
  • Run this. ideone.com/BC5w3u Commented Sep 23, 2014 at 9:58
  • Possible duplicate stackoverflow.com/questions/13982870/… Commented Sep 23, 2014 at 10:04
  • System.out.println(new SimpleDateFormat("EEE MMM dd hh:mm:ss zzz yyyy").parse(st).toLocaleString()); System.out.println(new Date(new SimpleDateFormat("EEE MMM dd hh:mm:ss zzz yyyy").parse(st).getTime()).getTime()); System.out.println(new Date(new SimpleDateFormat("EEE MMM dd hh:mm:ss zzz yyyy").parse(st).getTime()).toLocaleString()); Commented Sep 23, 2014 at 10:09

4 Answers 4

4

java.sql.Date doesn't contain time information. You should look at java.sql.Timestamp instead

Sign up to request clarification or add additional context in comments.

Comments

0

As its name suggests, java.sql.Date is the Java equivalent of an SQL DATE meaning it stores years, months and days only -- no time data (as a result, note also that java.sql.Date isn't associated with a time zone).

Comments

0

try this:

java.sql.Timestamp ourJavaTimestampObject = new java.sql.Timestamp(dateTime.getTime().getTime()); 

with dateTime is an instance of Date. It works to me.

Comments

0

see this link

http://www.coderanch.com/t/304851/JDBC/databases/Java-date-MySQL-date-conversion

The following lines may solve your issue.

java.util.Date dt = new java.util.Date(); java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String currentTime = sdf.format(dt); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.