How to build this time format?

  • Follow


Greetings,

I am developing an application on Solaris 2.7 platform which C. Now I need
to encode/decode a time format as: YYMMDDhhmmsstnnp" where:

YY: last two digits of the year (00-99)
MM: month (01-12)
DD: day (01-31)
hh: hour (00-23)
mm: minute (00-59)
ss: second (00-59)
t: tenths of second (0-9, but can always be 0)
nn: Time difference in quarter hours between local (as expressed in the
first 13 octets) and UTC time (00-48)
p: '+' Local time is in quarter hours advanced in relation to UCT time
   '-' Local time in in quarter hours retarded in relation to UCT time

It's easy to build first 13 octets as local time, but how to get the "nn"
and "p"?

Thanks in advance!
Evan


0
Reply music4 10/10/2003 1:48:19 AM

"music4" <music4@163.net> writes:

> Greetings,
> 
> I am developing an application on Solaris 2.7 platform which C. Now I need
> to encode/decode a time format as: YYMMDDhhmmsstnnp" where:

Wrong. You're missing the centuries.

> nn: Time difference in quarter hours between local (as expressed in the
> first 13 octets) and UTC time (00-48)
> p: '+' Local time is in quarter hours advanced in relation to UCT time
>    '-' Local time in in quarter hours retarded in relation to UCT time
> 
> It's easy to build first 13 octets as local time, but how to get the "nn"
> and "p"?
> 
> Thanks in advance!

man localtime

Ok, I feel generous: man localtime | sed -e 's/.^H//g' | grep -C5 timezone

-- 
__Pascal_Bourguignon__
http://www.informatimago.com/
Do not adjust your mind, there is a fault in reality.
0
Reply Pascal 10/10/2003 5:03:15 AM


"Pascal Bourguignon" <spam@thalassa.informatimago.com> wrote in message
news:87ad89lm5o.fsf@thalassa.informatimago.com...

> man localtime
>
> Ok, I feel generous: man localtime | sed -e 's/.^H//g' | grep -C5 timezone

    That's not enough. This is actually a really complex problem. The
*current* GMT offset may not be the correct GMT offset for the time he's
trying to convert!

    DS


0
Reply David 10/10/2003 5:16:16 AM

On Fri, 10 Oct 2003 09:48:19 +0800, music4 wrote:

> Greetings,
> 
> I am developing an application on Solaris 2.7 platform which C. Now I need
> to encode/decode a time format as: YYMMDDhhmmsstnnp" where:
> 
> YY: last two digits of the year (00-99)
> MM: month (01-12)
> DD: day (01-31)
> hh: hour (00-23)
> mm: minute (00-59)
> ss: second (00-59)
> t: tenths of second (0-9, but can always be 0)
> nn: Time difference in quarter hours between local (as expressed in the
> first 13 octets) and UTC time (00-48)
> p: '+' Local time is in quarter hours advanced in relation to UCT time
>    '-' Local time in in quarter hours retarded in relation to UCT time
> 
> It's easy to build first 13 octets as local time, but how to get the "nn"
> and "p"?

 For decoding, life is relatively simple as you are allowed to overflow
the fields that you pass to mktime(). So you just do...

tm = gmtime()
tm->... = ...; /* parse values, including adding the 15 periods to
                * _hour and _min */
epoch_timestamp = mktime(tm);

....encoding requires more work, as you'll need to build a epoch_timestamp
for both a local encoding and a UTC (gmtime) encoding and then get the
difference between them in seconds. Then encode that in 15 minute
intervals as you wish.

-- 
James Antill -- james@and.org
Need an efficient and powerful string library for C?
http://www.and.org/vstr/

0
Reply James 10/10/2003 4:39:03 PM

3 Replies
334 Views

(page loaded in 0.069 seconds)

Similiar Articles:













7/24/2012 9:15:01 PM


Reply: