java - Same value from database gives different long when code run locally and on server -
i have field in db name updation_date , save data in datetime/ timestamp , saving utc datetime. when retrieve long values this
rs.gettimestamp("updation_date").gettime()
now when run code on local machine right utc time (the same 1 saved in db) when run same code on server (it's in netharlands) long value having 3 hours utc time. don't know why difference because converting time db long.
updation: tried using function utc date still no effect
private static string dateformat = "yyyy-mm-dd't'hh:mm:ssz"; public static long getutctime(timestamp datetime) throws parseexception{ simpledateformat sdf = new simpledateformat(dateformat); sdf.settimezone(timezone.gettimezone("utc")); date date = sdf.parse(getstringdate(datetime)); return date.gettime(); } public static string getstringdate(timestamp datetime) throws parseexception { simpledateformat sdf = new simpledateformat(dateformat); return sdf.format(new date(datetime.gettime())); }
and save long
setupdationdate(constants.getutctime(rs.gettimestamp("updation_date"));
from javadoc:
sets designated parameter given java.sql.timestamp value, using given calendar object. driver uses calendar object construct sql timestamp value, driver sends database. calendar object, driver can calculate timestamp taking account custom time zone. if no calendar object specified, the driver uses default time zone, of virtual machine running application.
Comments
Post a Comment