Adam Varhegyi
Adam Varhegyi

Reputation: 9894

Calendar's getTime() method gives back wrong hours

Well i would like to simply get the current date in my app.

I use this snippet:

Calendar cal = Calendar.getInstance();
cal.getTime().toGMTString();

for some reason it gives me like: "22 Feb 2013 18:00:48 GMT"

Well it is 19:00 right now in Hungary, not 18:00, There is 1 hour difference.

What the heck ? :) How can i implement a reliable way to always get the current date?

Upvotes: 0

Views: 528

Answers (2)

Adam Varhegyi
Adam Varhegyi

Reputation: 9894

Thanks for replies, i shouldnt use GMT. Instead of that:

 cal.getTime().toLocaleString();

Upvotes: 0

Jave
Jave

Reputation: 31846

Well, Hungary is GMT+1, that's where the missing hour went. The toGMTString() is deprecated, and you should instead use the DateFormat.format()-method.

Upvotes: 3

Related Questions