-1

I'am using GregorianCalendar class to manipulate with date and time. I need to get only a current date without time. My code:

        Calendar today = new GregorianCalendar();
        today.set(GregorianCalendar.HOUR,0);
        today.set(GregorianCalendar.MINUTE,0);
        today.set(GregorianCalendar.SECOND,0);
        today.set(GregorianCalendar.MILLISECOND,0);
        Date todayDate = new Date();
        todayDate.setTime(today.getTime().getTime());

I expect todayDate will be like this "Wed Dec 07 00:00:00 EET 2016" But actually todayDate is "Wed Dec 07 12:00:00 EET 2016".

Which is the correct way to do it?

Ia understend difference between fields HOUR and HOUR_OF_DAY when I get value, but why when I set value of HOUR to "0" the HOUR_OF_DAY is not seting to "0" automatically. Zero is always zero...

Question is about Data integrity...

Dmitry
  • 133
  • 1
  • 7
  • Possible duplicate of [Difference between Calendar.HOUR and Calendar.HOUR\_OF\_DAY?](http://stackoverflow.com/questions/37236381/difference-between-calendar-hour-and-calendar-hour-of-day) – Selvin Dec 07 '16 at 16:21
  • you had set HOUR but didn't change AP/PM ... check the code in the morning :P – Selvin Dec 07 '16 at 16:21
  • O... I found my mistake. I thought zero is always zero... but it is not true for hours after midday :). Thank You! – Dmitry Dec 08 '16 at 09:31

1 Answers1

0

It is a mistake to thought zero is always zero... It is not true for hours after midday. Zero hours after midday in short form (am/pm) is 12 hours in 24 form.

Thanks to @selvin

Community
  • 1
  • 1
Dmitry
  • 133
  • 1
  • 7