My application expects and returns date in a particular format(yyyy-MM-dd'T'HH:mm:ss'.'S).
This application runs at US. Similar instances of the same application run from different parts of the world(different time zones). I want to store all application data in a single database with GMT format.
To insert a record into database, since the application returns the date in a particular format, I am first converting the time to GMT using code like this
dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
ParsePosition parsePos = new ParsePosition(0);
date = dateFormat.parse("2008-08-04T18:00:13",parsePos);
if( date != null )
{
date_utc = String.valueOf(date.getTime());//which I am assuming will give equivalent time at GMT
}
return date_utc;
This code will return the result as "1217853013000"
Now since I cannot store this integer value in database, I want to convert this into application's format (yyyy-MM-dd'T'HH:mm:ss'.'S).
For this, the code I worte is
Double datevalD = new Double("1217853013000");
date = new Date(datevalD.longValue());
dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'S");
FieldPosition fieldPos = new FieldPosition(0);
StringBuffer dateString= new StringBuffer();
dateString = dateFormat.format(date,dateString,fieldPos);
convertedDate = dateString.toString();
return convertedDate;
If I run this class at a location GMT+5:30,
the result is 2008-08-04T18:00:13.0. which is same as my input.
I am expecting date.getTime() to return me the time at GMT. So tried to just change the format of it(to yyyy-MM-dd'T'HH:mm:ss'.'S
).
Whats going wrong?? Is my assumption wrong that I should not use date.getTime() as it is being used?
Please help.