Re: Discrepancy in current hour
On Mar 21, 12:39 am, Rhino <rch...@ymail.com> wrote:
On Mar 20, 11:59 pm, Lew <no...@lewscanon.com> wrote:> Rhino wrote:
I am happy to learn more about Java and improve my code but getting
told to do it one way, spending time to do it, then being told to
change it all back to the way it was is frustrating to say the least.
No one told you to "change it all back to the way it was". You prese=
nted a
whole bunch of complicated code at one point that was dragging out inte=
gers
from Calendar fields and padding them with characters into Strings. =
All that
messy conversion seemed better suited to use of DateFormat. As a sep=
arate
question, I asked why you were wrapping a simple call to
Calendar.get(Calendar.HOUR), a small piece of the overall stringificati=
on
process only. Separate issue, and a question, not advice.
I'm starting to see what was meant now. You were reacting to my little
home-grown pad() method that put leading zeroes on the date components
when needed and then turned the whole thing into a String. And ONLY
that. I thought the advice I was getting was that ALL of the code was
crap and should all be redone to use DateFormat and SimpleDateFormat.
This ordeal has already dragged on long enough so I just decided to
take it on faith that DateFormat and SimpleDateFormat were "better"
somehow and not question it in the interests of time. (I might have
asked about it somewhere down the road.)
And again, when you mentioned using Calendar again, I thought you were
saying that Calendar was better after all and now all the code should
be based on Calendar instead of DateFormat/SimpleDateFormat.
I'm not going to point fingers here and blame this on you or the
others who are trying to help. I'll just chalk it up to an honest
misunderstanding. Like I said, I'm not stupid but I'm not a psychic
either. And neither are any of you. We all know what we had in mind
when we wrote what we wrote but we can't know how the other guy is
going to take it.
I'm just trying to be obliging here and accept what I'm being told
rather than make everyone justify their advice. I'm assuming you guys
know more than me. Maybe I have to start getting a little more
assertive and make you justify the changes you are asking me to
make....
How about distinguishing between advice ("Try X") and a request for
information ("Why Y?"). The latter assumes you have a reason for doi=
ng
something that the questioner has interest in knowing.
An example of advice:
Eric Sosman wrote:
Suggestions:
...
4) Learn to use the format() methods of PrintStream and/or
of String.
Lew wrote:
Or use java.text.DateFormat / SimpleDateFormat.
<http://java.sun.com/javase/6/docs/api/java/text/DateFormat.html>
<http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.htm=
l>
Those related to providing String representations.
An example of a request for information:
I wonder why you write a utility method to get the current hour
when the standard API already provides a one-line way to do so.
Advice there would have been redundant since you were already using the
technique in the body of your utility method, so clearly you knew of it=
.. It
was just one programmer looking to find out what another programmer's
reasoning was.
"Get the current hour" is a different task from "provide a String
representation of a Calendar instance". Advice appropriate to one ta=
sk might
not apply to the other.
Fair enough.
Now back to the question at hand. Do you see anything here that makes
you think the Java code is wrong in some way? I'm still leaning
strongly to the OS as being the culprit but I don't want to start
pestering the Windows experts until I can say that we have looked over
the Java code thoroughly and are satisfied that this IS an OS issue.
Otherwise, I'm going to bouncing back and forth like a frigging
pingpong ball between Windows and Java experts.....
--
Rhino
Just to bring everything up to date, I have made the recommended
changes in the Java code.
1. I amended the getCurrentTime() method to use SimpleDateFormat.
2. I reverted the getCurrentHour methods to use GregorianCalendar.
3. I changed TestHour and TestHour2 so that they start like this:
------------------------------------------------------
public class TestHour {
final static boolean DEBUG = true;
public static void main(String[] args) {
TestHour testHour = new TestHour();
testHour.showResults();
}
public TestHour() {
//empty
}
public void showResults() {
System.out.println("The current hour on the 12 hour clock is: " +
getCurrentHour12HourClock() + ".\n");
System.out.println("The current hour on the 24 hour clock is: " +
getCurrentHour24HourClock() + ".\n");
System.out.println("The current time is: " + getCurrentTime() + ".
\n");
}
//date/time methods omitted
}
------------------------------------------------------
When I run the tests again now, the results still show the hour being
one hour too late.
I'm going out of town now for a couple of days and won't be able to
get online to check this thread until late Monday night. I look
forward to seeing more helpful suggestions on my problem - and,
ideally, a final verdict on whether the problem is with Java or the OS
- on my return.
Thanks again for all the help!
--
Rhino