seconds actually suck as a time measure because of
leap seconds, If you don't allow for them you will be one "minute" fast (if
you don't round the seconds to get your minute...) and they are not
algorithmically predictable, so... fugetabout it....  check this out:

http://leapsecond.com/java/gpsclock.htm

your representation depends on the time scale. You are better off encoding
with y/m/d for longer term than using integer seconds.  For example:
16 bits/year, 4 bits/month, 5 bits/day, 17 bits/seconds

gives you second accurate representation over human history .... and you
still have 21 bits to play with in a 64 bit word, for payload, sub-second
times, or whatever.    More fun would be to divide the month in half-days,
so you get a 16-bit second quantity... you could also reduce the year range
to get more useful sub-second range...

Calculation and representation are two different issues.  Use system
functions for calculations, and best to store in UTC.   There are lots of
inanities in doing calculations/conversions yourself (like who the heck
tracks double daylight savings time used in WWII... )  time keeping is
political, and their ain't no algorithm for politics!



On Sun, Jan 2, 2011 at 11:39 AM, Peter <[email protected]> wrote:

> oops... forgot to add one to the month for humans... oh, well... in C, 0
> feels natural for january...
>
>
> On Sun, Jan 2, 2011 at 11:37 AM, Peter <[email protected]> wrote:
>
>> short version: man ctime.
>>
>> longer version:
>>
>> lola% more now.c
>>
>> #include <stdio.h>
>> #include <time.h>
>>
>> int main(int argc, char *argv[]) {
>>   time_t now;
>>   struct tm *d;
>>
>>   time(&now);
>>   printf("hello world. It is now %10ld seconds since the epoch began\n",
>>       now);
>>
>>   d = localtime(&now);
>>   printf("for mere humans, today is: %d/%d/%d\n",
>> 1900+d->tm_year,d->tm_mon, d->
>> tm_mday );
>> }
>> lola%
>>
>>
>> lola% ./now
>> hello world. It is now 1293986153 seconds since the epoch began
>> for mere humans, today is: 2011/0/2
>> lola%
>>
>>
>> On Sun, Jan 2, 2011 at 10:18 AM, Leslie S Satenstein <
>> [email protected]> wrote:
>>
>>> Happy New Year.
>>>
>>> I have been trying to find a simple example to retrieve the computer date
>>> using documented routines.
>>>
>>> I want to retrieve three integers corresponding to year, month and day.
>>>
>>> I took the time() function and subtracted the number of seconds we are
>>> behind GMT 0, and converted seconds to days since 1979-01-01
>>>
>>> From there I did calculate the current date. However, rather than
>>> supporting my own code, I would have liked to have use localtime(), and
>>> time(), etc, but...
>>>
>>> I get compile errors for tm->year, tm->mon and tm->mday.
>>>
>>> Searching the includes, results in no function that returns the integters
>>> Ditto for a google search.
>>>
>>> Any standard function to complete and return the tm  structure as defined
>>> in time.h would be appreciated.
>>>
>>>
>>> ------------------
>>>
>>> Regards
>>>  Leslie
>>>  Mr. Leslie Satenstein
>>> 40 years in IT and going strong.
>>> Yesterday was a good day, today is a better day,
>>> and tomorrow will be even better.
>>>
>>> mailto:[email protected]
>>> alternative: [email protected]
>>> www.itbms.biz / www.eclipseguard.com
>>>
>>> _______________________________________________
>>> mlug mailing list
>>> [email protected]
>>> https://listes.koumbit.net/cgi-bin/mailman/listinfo/mlug-listserv.mlug.ca
>>>
>>
>>
>
_______________________________________________
mlug mailing list
[email protected]
https://listes.koumbit.net/cgi-bin/mailman/listinfo/mlug-listserv.mlug.ca

Reply via email to