mysql - Java: resultSet.getTimestamp loses time -


i have following entry in database:

start                   end 2013-08-25 14:23:20     2013-09-14 14:23:20 

(type datetime, database mysql)

and in java application want set date , time calendar followed:

java.sql.timestamp timestampstart = inresults.gettimestamp("start"); system.out.println("start: " + timestampstart); calendar start = new gregoriancalendar(); start.settime(timestampstart); 

edit:

added system.out.println code:

start: 2013-08-25 15:11:08.0 end: 2013-09-14 15:11:08.0 (same code start) 

now thing is, time lost when call inresults.gettimestamp. correct date, time time queried executed instead of time in database.

any ideas?

no argument constructor

constructs default gregoriancalendar using current time in default time zone default locale.

you can create java.util.date timestamp gethours(), getminutes(), , getseconds() date , use in calendar's constructor. signature below.

gregoriancalendar(int year, int month, int dayofmonth, int hourofday, int minute, int second) 

something this:

    java.sql.timestamp timestampstart = inresults.gettimestamp("start");      java.util.date d = new java.util.date(timestampstart.gettime());     calendar start = new gregoriancalendar(d.getyear(), d.getmonth(), d.getdate(), d.gethours(), d.getmminutes(), d.getseconds()); 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -