Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #18601
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2012-09-07 18:44 -0700 |
| References | <3a69eb4a-f3c0-4b56-9a67-6833ccb2a1c8@googlegroups.com> <nospam-D06BA0.20534806092012@news.aioe.org> <3931f4ca-a41a-489a-8521-545eaed21742@googlegroups.com> <nospam-64D325.21022107092012@news.aioe.org> |
| Message-ID | <816d0737-3c2e-476a-9a56-41a13964fe5a@googlegroups.com> (permalink) |
| Subject | Re: Date/Calendar confusion |
| From | Lew <lewbloch@gmail.com> |
John B. Matthews wrote: > Lew wrote: >> John B. Matthews wrote: >>> Ulrich Scholz wrote: > > [Valuable clarifications elided.] > >>> calendar2.set(Calendar.YEAR, 1970); >>> calendar2.set(Calendar.MONTH, Calendar.JANUARY); >>> calendar2.set(Calendar.DAY_OF_MONTH, 1); >>> >>> calendar2.clear(Calendar.HOUR); >> >> Better: 'calendar2.set(Calendar.HOUR, 0);' > > Can I impose on you to amplify further? Is this related to "the > resolution rule for the time of day," mentioned in clear(int)? > > <http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#time_resolution> > <http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#clear(int)> I guess, but that's not my focus. My focus is on the fact that when you 'clear(int)', as opposed to 'set(int,int)', the 'Calendar' instance does no reconciliation, nor can you rely on any specific field value such as '0'. 'clear()' sets fields to *undefined*, not a specific value. It makes no attempt to reconcile field values, e.g., to set a day to a valid value based on the month value or vice versa. So you have no promise as to what the values are after a 'clear()'. What comes out might well surprise, as it did on that project some years ago where I encountered this situation. -- Lew
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Date/Calendar confusion Ulrich Scholz <d7@thispla.net> - 2012-09-06 01:03 -0700
Re: Date/Calendar confusion nogales <nogales.manuel@gmail.com> - 2012-09-06 02:29 -0700
Re: Date/Calendar confusion Lew <lewbloch@gmail.com> - 2012-09-06 10:21 -0700
Re: Date/Calendar confusion "John B. Matthews" <nospam@nospam.invalid> - 2012-09-06 20:53 -0400
Re: Date/Calendar confusion Lew <lewbloch@gmail.com> - 2012-09-07 11:01 -0700
Re: Date/Calendar confusion "John B. Matthews" <nospam@nospam.invalid> - 2012-09-07 21:02 -0400
Re: Date/Calendar confusion Lew <lewbloch@gmail.com> - 2012-09-07 18:44 -0700
Re: Date/Calendar confusion "John B. Matthews" <nospam@nospam.invalid> - 2012-09-08 09:12 -0400
Re: Date/Calendar confusion Lew <lewbloch@gmail.com> - 2012-09-08 16:51 -0700
csiph-web