Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

when converting timestamp to java.sql.date time is getting delay by 12 hrs between 12pm -1pm in day

 
Ravi Kommuri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

i am facing a problem in converting timestamp to sql date.

can some one help to resolve the issue.

Code:

1. String time= Calendar.getInstance().getTime().toString().split(" ")[3];
2.Date convDate = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(utility.getTimestampWithTime(dateFormat, StringUtility.noNull(request.getParameter("exchRateDate")),time).toString());
3. java.sql.Date sqlDate = new java.sql.Date(convDate.getTime());

till step 2 date and time is correct

in step 3 we are convering to sql date and inserting in data base (column type DATE)

time is inserting wrongly in 12pm to 1pm in a day

e.g i am doing operation at 12:15pm

the data is storing as 12:15 am in data base
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the date/time pattern in SimpleDateFormat. HH vs hh
 
Ravi Kommuri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you K. Tsang

it is working correct now.

may i know the reason behind the HH vs hh exactly ? and y this problem only during 12pm to 1pm in a day
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you check out the javadoc for SimpleDateFormat? The answer is there.
 
Ravi Kommuri
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic