OK, so I switched to HOUR_OF_DAY and that seems to work. Thanks!
But I'm still confused as to why I get the correct time under NT and not
under Blackdown when I use HOUR.
I'm not adding to the current time, at least as far as the documentation
goes. I'm calling set(), not add(), and furthermore I'm setting the AM/PM
value appropriately. The behaviour seems to indicate that AM and PM are
switched somewhere in the code.
Anyway...
J
>It looks like you are trying to add hours to the current time.
>If thats the case then just do the following:
>
>c.setTime (new Date());
>c.add (Calendar.HOUR_OF_DAY, Integer.parseInt (inArgv [0]));
>
>Also, take a look at the GregorianCalendar Class for some other
>nifty calendar features.
>
>Hope this helps.
>
>Jason Proctor wrote:
>>
>> I'm having some trouble getting Calendar to do what I want it to. With the
>> following source -
>>
>> public class Hack
>> {
>> public static void
>> main (String inArgv [])
>> {
>> Calendar c = Calendar.getInstance ();
>>
>> c.setTime (new Date ());
>>
>> int hours = Integer.parseInt (inArgv [0]);
>>
>> if (hours > 11)
>> {
>> c.set (Calendar.HOUR, hours);
>> c.set (Calendar.PM, 1);
>> }
>> else
>> {
>> c.set (Calendar.HOUR, hours);
>> c.set (Calendar.AM, 1);
>> }
>>
>> System.out.println (c.getTime ());
>> }
>> }
>>
>> On RedHat 5.2, Blackdown 1.2pre1, I get the following output -
>>
>> java Hack 11
>> Wed Apr 07 23:56:04 PDT 1999
>> java Hack 15
>> Fri Apr 08 03:56:20 PDT 0001
>>
>> On NT, I get the following output -
>>
>> java Hack 11
>> Wed Apr 07 11:53:53 PDT 1999
>> java Hack 15
>> Thu Apr 07 15:53:59 PDT 0001
>>
>> It appears that AM and PM are getting confused somewhere. Am I using
>> Calendar correctly?
>>
>> Thanks in advance.
>>
>> J
>>
>> ----------------------------------------------------------------------
>> To UNSUBSCRIBE, email to [EMAIL PROTECTED]
>> with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
>
>--
>Keith Spainhour 919-472-5673
>Software Engineer [EMAIL PROTECTED]
>Cisco Systems http://www.cisco.com
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]