I have a field in my db name as updation_date and i save data in it as datetime/ timestamp and i am saving UTC datetime. Now when i retrieve the long values i do this
rs.getTimestamp("UPDATION_DATE").getTime()
Now when i run the code on my local machine i get the right UTC time (the same one i saved in db) but when i run the same code on my server (it's in Netharlands) i get long value but having 3 hours extra then UTC time. I don't know why i get the difference because i just converting the time i get from db to long.
Updation: I tried using this function to get UTC date but 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 now save long like this
setUpdationDate(Constants.getUTCTime(rs.getTimestamp("UPDATION_DATE"));