[comp.unix.wizards] Convert string time into seconds?

wk@hpirs.HP.COM (Wayne Krone) (07/08/89)

> I have a user entered time/date in the format:
> yymmddhhmmss
> I need to convert this into seconds since the epoch and

If you have ANSI C libraries, convert the yymmddhhmmss into a tm struct
and then use mktime() to convert that into seconds since the epoch.

Wayne

lance@lancelot (Lancelot of Caid) (07/11/89)

In article <4760015@hpirs.HP.COM>, wk@hpirs.HP.COM (Wayne Krone) writes:
< > I have a user entered time/date in the format:
< > yymmddhhmmss
< > I need to convert this into seconds since the epoch and
< 
< If you have ANSI C libraries, convert the yymmddhhmmss into a tm struct
< and then use mktime() to convert that into seconds since the epoch.
< 
< Wayne
What if you DON'T have ANSI C libs?
What if you only have SCO 386 Xenix libs?
What can a person do then????

Anyone got a lib set that WILL do this that I can get? (source?)

Thanks,

lance@lancelot (Lancelot of Caid) (07/11/89)

sorry. Forgot the .sig file :)


Lance Ellinghouse (A.K.A Lancelot of Caid)
"Life is a game of Chess, some are Kings, some Queens, some pawns, and
 some just get taken." - Lancelot
ucla-an!hermix!lancelot!lance; ucla-an!hermix!lancelot!lance@ee.UCLA.EDU

smb@ulysses.homer.nj.att.com (Steven M. Bellovin) (07/11/89)

In article <303@lancelot>, lance@lancelot (Lancelot of Caid) writes:
> In article <4760015@hpirs.HP.COM>, wk@hpirs.HP.COM (Wayne Krone) writes:
> < > I have a user entered time/date in the format:
> < > yymmddhhmmss
> < > I need to convert this into seconds since the epoch and
> What if you DON'T have ANSI C libs?

I answered the original posting by email; I'll repeat it publicly.
At the cost of a few small syntactic rewrites of that string,
getdate() -- part of the netnews src, and in the public domain since
I wrote it lo these many years ago -- can do the job.  It's overkill,
but it will work if you don't want to take the time to do it right
for this particular case.

		--Steve Bellovin

vic@zen.co.uk (Victor Gavin) (07/12/89)

In article <4760015@hpirs.HP.COM> wk@hpirs.HP.COM (Wayne Krone) writes:
>If you have ANSI C libraries, convert the yymmddhhmmss into a tm struct
>and then use mktime() to convert that into seconds since the epoch.
>
>Wayne

Is there an ANSI C/Posix/WhateverStandardYouCareToNominate function that will
convert from a time in a string (as produced by asctime()/ctime()) ?

[[I've always wanted one for those odd occasions, but have (up to now) been
able to do without]]

			vic
--
Victor Gavin						Zengrange Limited
vic@zen.co.uk						Greenfield Road
..!mcvax!ukc!zen.co.uk!vic				Leeds England
+44 532 489048						LS9 8DB

guy@auspex.auspex.com (Guy Harris) (07/15/89)

>Is there an ANSI C/Posix/WhateverStandardYouCareToNominate function that will
>convert from a time in a string (as produced by asctime()/ctime()) ?

No, but you could snatch the "getdate" function from, among other
places, the netnews source (as Steve Bellovin, author of that function,
may already have noted); it uses a YACC parser to accept quite a number
of time formats, and if it doesn't handle "asctime()" format you can
probably whack it to do so.

It currently does the equivalent of what "mktime()" does itself, but you
could rewhack it to use "mktime()", at the expense of possibly
eliminating its ability to parse dates with explicit time zone
specifications in them. 

wk@hpirs.HP.COM (Wayne Krone) (07/15/89)

> >If you have ANSI C libraries, convert the yymmddhhmmss into a tm struct
> >and then use mktime() to convert that into seconds since the epoch.
> >
> >Wayne
> 
> Is there an ANSI C/Posix/WhateverStandardYouCareToNominate function that will
> convert from a time in a string (as produced by asctime()/ctime()) ?

Not that I'm aware of.  I'll start a discussion in X/Open to see if
we can address this need.  A function that would convert local (German,
Japanese, ...) date/time strings as well as the asctime() string
would be useful.

Wayne