Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Creating a Calendar without a TimeZone

I would like to start by saying that I've read several threads similar to this one, but none of them really solved my problem. I would also like to state that I've tried to use SimpleDateFormat and joda.DateTime without any success.

The problem is the following:

I have a Calendar object that holds the information about a specific date: 2008-04-30T00:00:00Z When using the calendar.getTime() method I can get different results because I know that that method is looking for the local value

Thus:

UK: 2008-04-30T01:00:00.000+0100

US: 2008-04-30T20:00:00.000-0400

But I would like to get a Date object that holds just the Date and Time values "2008-04-30T00:00:00" ignoring completely any timezone.

How can I do that?

As I mentioned before I tried to use SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss") but I always end up with the same results.

Any help would be really appreciated Cheers.

like image 246
MaLLinok Avatar asked Dec 06 '22 13:12

MaLLinok


1 Answers

Found out that you can clear the Timezone by using code below:

Calendar cal = Calendar.getInstance(); cal.clear(Calendar.ZONE_OFFSET);

like image 55
GuestOnly Avatar answered Dec 09 '22 01:12

GuestOnly