Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!

# Calendar Output

AnuragSingh Kumar
Greenhorn
Posts: 5
Hi

I have a code as

where i try to set time in the format specified.
But when i do a print of cal i get some values which are different from my set value as
HOUR_OF_DAY=13, [OK]
MINUTE=10, [Not OK]
SECOND=12, [Not OK]
MILLISECOND=17 [Not OK]
.
Also 5th jan 2011 was wed day but the output was
DAY_OF_WEEK=2
I cannt get where does this difference come from. Can i get some help please..

Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
One thing that is wrong is that you define the milliseconds value with 6 digits. Milliseconds are thousandths of a second - it can have at most 3 digits (because when it goes over 1000, it's one second).

301017 milliseconds is 301 seconds and 17 milliseconds. And that explains exactly what's happening here: the time is 13 hours, 5 minutes, 11 seconds plus 301 seconds and 17 milliseconds = 13:05:11 plus 5 minutes, 1 second, 17 ms = 13:10:12.017 -> so hours = 13, minutes = 10, seconds = 12, ms = 17, exactly what you're getting.

AnuragSingh Kumar
Greenhorn
Posts: 5

Thank you Jesper
This solves the minute and second problem . But i still have this DAY_OF_WEEK=2 which should be 4.

Riaan Nel
Ranch Hand
Posts: 160
AnuragSingh Kumar wrote:

Thank you Jesper
This solves the minute and second problem . But i still have this DAY_OF_WEEK=2 which should be 4.

Look at the code you posted - are you sure that you want to be looking at the year 2111, rather than 2011?

AnuragSingh Kumar
Greenhorn
Posts: 5
Oh!! Sorry for that.
And thanks again for the help