The codes you use to specify the date format when you create a SimpleDateFormat object are case-sensitive. So "DD-MM-YYYY HH:MM:SS" doesn't mean what you think it means. Lookup the documentation for SimpleDateFormat for information on how to specify the format.
Also, the "MM" you use for the months is not going to match three-letter month abbreviations like "Dec".
As I said before, the Date class has no concept of timezones, therefore Date.toString is not likely to do the right thing. Use DateFormat.format instead, and make sure to set its timezone (which the code currently is not doing).
Somnath Mallick wrote:^^Well at least, Well do you mean to say that i should change it like this?
Yes, but note that hh (lower-case) for the hours means the hour in AM/PM (1-12) - this will fail if hours is 17. Try this:
Somnath Mallick wrote:But still all the dates are printing in IST!
Yes, because Date.toString() uses the local timezone setting of your system - it displays the Date object in your local timezone. Instead of using Date.toString(), format the date object using a DateFormat object; set the timezone that you want your date displayed in on the DateFormat object. As Ulf said, class Date itself doesn't know about timezones.
Joined: Mar 04, 2009
I hope this is correct? But when the time is printing no time zone is getting printed so i cant really say the times are really in GMT or IST.
Also when i am trying to insert this value in an excel sheet using POI API, i had to convert all time values to string, so all the data entered in the Excel sheet is IST!