Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.development.apps > #409

Re: time conversion

From Bill M <wpmccormick@just_about_everywhere.com>
Newsgroups comp.os.linux.development.apps
Subject Re: time conversion
Date 2012-01-27 08:19 -0600
Organization A noiseless patient Spider
Message-ID <jfubqh$59n$1@dont-email.me> (permalink)
References <jfsjn2$4hm$1@dont-email.me> <87zkda131v.fsf@araminta.anjou.terraraq.org.uk> <jfu8b9$7u2$2@nntp.ts.fujitsu.com> <87liot5k5h.fsf@araminta.anjou.terraraq.org.uk>

Show all headers | View raw


Richard Kettlewell wrote, On 1/27/2012 7:50 AM:
> Josef Moellers<josef.moellers@ts.fujitsu.com>  writes:
>> Am 27.1.2012 schrub Richard Kettlewell:
>>> Bill M<wpmccormick@just_about_everywhere.com>  writes:
>
>>>> What is the easiest way to convert a time value that is the number
>>>> of microseconds that have elapsed since 0000 hours 1 January 1972 into
>>>> the unixepoch (the number of seconds since 0000 hours 1 January 1970).
>>>
>>> Divide by one million and subtract 63072000?
>>>
>>> You'll need to correct for leap seconds if your input value uses
>>> different rules from time_t.
>>
>> In that case, I'd suggest using mktime to convert 0:00:00 1/1/72 to
>> time_t and subtract^Wadd *that* value.
>
> If you mean that as a suggest to help with leap seconds (supposing that
> is necessary for the OP), it won't.
>
> If you just mean it as a way of calculating the offset, sure, you can
> work it out on the fly or you can use a constant, the result is the same
> either way.
>

I was looking for some built in function, before giving it much thought. 
The Divide / add is simple enough. The number of useconds must already 
account for leaps.

#define PLC_TIME_ADJUST(t) ((t/1000000) + 63072000)
unsigned int lowWord = strtol(tagValues[0], NULL, 10);
unsigned long long highWord = strtoll(tagValues[1], NULL, 10);
unsigned long long unixTime = PLC_TIME_ADJUST(((highWord << 32) + lowWord));
	
Thanks!!

Back to comp.os.linux.development.apps | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

time conversion Bill M <wpmccormick@just_about_everywhere.com> - 2012-01-26 16:22 -0600
  Re: time conversion Richard Kettlewell <rjk@greenend.org.uk> - 2012-01-26 23:01 +0000
    Re: time conversion Richard Kettlewell <rjk@greenend.org.uk> - 2012-01-27 09:18 +0000
    Re: time conversion Josef Moellers <josef.moellers@ts.fujitsu.com> - 2012-01-27 14:20 +0100
      Re: time conversion Richard Kettlewell <rjk@greenend.org.uk> - 2012-01-27 13:50 +0000
        Re: time conversion Bill M <wpmccormick@just_about_everywhere.com> - 2012-01-27 08:19 -0600
  Re: time conversion Jasen Betts <jasen@xnet.co.nz> - 2012-01-28 21:15 +0000
    Re: time conversion Bill M <wpmccormick@just_about_everywhere.com> - 2012-01-31 14:34 -0600

csiph-web