??? 09/05/12 16:03 Read: times |
#188240 - Error in conversion from Unix EPOCH |
Created this code based on a pseudo code from a Dallas application note to convert an unsigned long to year-month-date-time format. Its working but instead of the month showing as Sept it shows as October. Not sure where is the bug :
unsigned long set_Epoch_s( unsigned long year, unsigned long month, unsigned long day, unsigned long hour, unsigned long min, unsigned long sec) { unsigned long DMonth[13] = { 0,31,59,90,120,151,181,212,243,273,304,334,365}; unsigned long iday; unsigned long temp; iday = 365 * ( year - 1970) + DMonth[month] + ( day-1); // days since 1/1/1970 iday = iday + ( year - 1969)/4; // + leap days since 1/1/1970 temp = year % 4; if ( ( month > 2 ) && (temp ==0)) // if leap year & past Feb.. { iday = iday + 1; } return (sec +( 60 * ( min + (60 * ( hour + (24 * iday )))))); //Compute seconds since } When I call the function with an argument of (2012, 9, 5, 17, 45, 0) I get a value of 1349459100 which is "Oct 5th 2012 , 17:45:00 " . All except the month are correct. So what is the mistake that I am doing ( apart from creating a struct for the argument ..;-) Thanks Raghu |
Topic | Author | Date |
Error in conversion from Unix EPOCH | 01/01/70 00:00 | |
zero | 01/01/70 00:00 | |
DMonth[month-1] ???? | 01/01/70 00:00 | |
Stefan is correct and... | 01/01/70 00:00 | |
+4 - 100 + 400 | 01/01/70 00:00 | |
right, but... | 01/01/70 00:00 | |
88 years is a long time | 01/01/70 00:00 | |
That is what they said in the 60's | 01/01/70 00:00 | |
Thanks. Problem solved | 01/01/70 00:00 | |
Cross-checking important | 01/01/70 00:00 | |
Just a foot note about the year | 01/01/70 00:00 | |
?back conversion | 01/01/70 00:00 | |
No - multiplier should not be 366 | 01/01/70 00:00 | |
Running out of seconds > 1970 | 01/01/70 00:00 | |
signed is actually common - to support dates before 1970 | 01/01/70 00:00 | |
Will You Now. | 01/01/70 00:00 | |
Have you considered leap seconds? | 01/01/70 00:00 | |
Leap seconds can almost always be ignored | 01/01/70 00:00 | |
Time is passing anyway or is it just an illusion? | 01/01/70 00:00 | |
Missiles? Leap seconds contra way larger drift... | 01/01/70 00:00 | |
No such thing as a free lunch! | 01/01/70 00:00 | |
Link? | 01/01/70 00:00 |