By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,301 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,301 IT Pros & Developers. It's quick & easy.

time

P: n/a
Is there a standard library (C or C++) to convert a time in seconds since
Jan, 1st 1970 into a formatted datetime string ?
Jul 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Flzw wrote:
Is there a standard library (C or C++) to convert a time in seconds since
Jan, 1st 1970 into a formatted datetime string ?


No. Standard calendar time doesn't necessarily represent the number of
seconds since Jan 1st, 1970. However, there are standard functions to
convert standard calendar time value into a string. See 'asctime'.

What FM do you R (as in RTFM) on the regular basis that doesn't describe
'asctime' among other standard time functions?
Jul 22 '05 #2

P: n/a
Victor Bazarov wrote:
Flzw wrote:
Is there a standard library (C or C++) to convert a time in seconds
since Jan, 1st 1970 into a formatted datetime string ?


No. Standard calendar time doesn't necessarily represent the number of
seconds since Jan 1st, 1970. However, there are standard functions to
convert standard calendar time value into a string. See 'asctime'.

What FM do you R (as in RTFM) on the regular basis that doesn't describe
'asctime' among other standard time functions?


Not everyone learns from FMs. Even so, I don't know if they all have
adequate indexes. And even so, asctime doesn't answer the OP's question.

FWIW, the relevant man page on my (Mac OS X) box gives

"The functions ctime(), gmtime() and localtime() all take as an argument
a time value representing the time in seconds since the Epoch (00:00:00
UTC, January 1, 1970; see time(3))."

Does this mean that it's describing the local implementation rather than
the standard? It also mentions that asctime works with struct tm, not
with standard calendar time values; the equivalent function for working
with the latter is ctime.

Moreover, the OP might be wanting some control over the format, or
(which would be OT here) to use the OS-configured format. I for one
would certainly choose either over the peculiar Www Mmm dd hh:mm:ss yyyy
format I'm made to wonder where came from.

Stewart.

--
My e-mail is valid but not my primary mailbox. Please keep replies on
the 'group where everyone may benefit.
Jul 22 '05 #3

P: n/a
Stewart Gordon wrote:
Victor Bazarov wrote:
Flzw wrote:
Is there a standard library (C or C++) to convert a time in seconds
since Jan, 1st 1970 into a formatted datetime string ?

No. Standard calendar time doesn't necessarily represent the number of
seconds since Jan 1st, 1970. However, there are standard functions to
convert standard calendar time value into a string. See 'asctime'.

What FM do you R (as in RTFM) on the regular basis that doesn't describe
'asctime' among other standard time functions?

Not everyone learns from FMs. Even so, I don't know if they all have
adequate indexes. And even so, asctime doesn't answer the OP's question.


It doesn't?
FWIW, the relevant man page on my (Mac OS X) box gives

"The functions ctime(), gmtime() and localtime() all take as an argument
a time value representing the time in seconds since the Epoch (00:00:00
UTC, January 1, 1970; see time(3))."

Does this mean that it's describing the local implementation rather than
the standard?
Yes, unfortunately. I say 'unfortunately' because it fails to admit that.
It also mentions that asctime works with struct tm, not
with standard calendar time values; the equivalent function for working
with the latter is ctime.
Yes. How did you find that out? Can't be from TFM...
Moreover, the OP might be wanting some control over the format, or
(which would be OT here) to use the OS-configured format. I for one
would certainly choose either over the peculiar Www Mmm dd hh:mm:ss yyyy
format I'm made to wonder where came from.


Then the OP's choice should be 'strftime'. And that, too, can be seen and
learned _about_ from TFM.

V
Jul 22 '05 #4

P: n/a
Victor Bazarov wrote:
Stewart Gordon wrote:
Victor Bazarov wrote:
Flzw wrote:

Is there a standard library (C or C++) to convert a time in seconds
since Jan, 1st 1970 into a formatted datetime string ?
<snip> Not everyone learns from FMs. Even so, I don't know if they all have
adequate indexes. And even so, asctime doesn't answer the OP's question.


It doesn't?


Yes. Read it again. The OP asked specifically how to translate times
given in seconds since 1 Jan 1970.

<snip>
It also mentions that asctime works with struct tm, not
with standard calendar time values; the equivalent function for
working with the latter is ctime.


Yes. How did you find that out? Can't be from TFM...


As I said, from the man page. Do you have access to any flavour of
Unix? Type

man asctime

at its command prompt. Alternatively, look here:

http://www.die.net/doc/linux/man/man3/asctime.3.html

(One page describes asctime, ctime, gmtime, localtime and mktime, so it
doesn't really matter by which of those names you try to access the page.)
Moreover, the OP might be wanting some control over the format, or
(which would be OT here) to use the OS-configured format. I for one
would certainly choose either over the peculiar Www Mmm dd hh:mm:ss
yyyy format I'm made to wonder where came from.


Then the OP's choice should be 'strftime'. And that, too, can be seen and
learned _about_ from TFM.


Maybe it's easy to find stuff in _T_FM, but not so easy to find stuff in
the OP's particular FM. Yes, I know there's also stuff to be found on
the WWW....

Stewart.

--
My e-mail is valid but not my primary mailbox. Please keep replies on
the 'group where everyone may benefit.
Jul 22 '05 #5

P: n/a
Stewart Gordon wrote:
Victor Bazarov wrote:
Stewart Gordon wrote:
Victor Bazarov wrote:

Flzw wrote:

> Is there a standard library (C or C++) to convert a time in seconds
> since Jan, 1st 1970 into a formatted datetime string ?
<snip>
Not everyone learns from FMs. Even so, I don't know if they all have
adequate indexes. And even so, asctime doesn't answer the OP's
question.

It doesn't?

Yes. Read it again. The OP asked specifically how to translate times
given in seconds since 1 Jan 1970.


Well, read my reply again. There is NO STANDARD FUNCTION to do that. My
suggestion to RTFM was so that the OP would try to figure out which of
the *Standard* functions would suit him, or, alternatively, which of the
implementation-specific ones would. I can't even guess what platform/OS
the OP is using. Can you?
<snip>
It also mentions that asctime works with struct tm, not
with standard calendar time values; the equivalent function for
working with the latter is ctime.

Yes. How did you find that out? Can't be from TFM...

As I said, from the man page. Do you have access to any flavour of
Unix? Type

man asctime


What is "man" here? Can't be "MANual", can it? Nah...

[..]
Moreover, the OP might be wanting some control over the format, or
(which would be OT here) to use the OS-configured format. I for one
would certainly choose either over the peculiar Www Mmm dd hh:mm:ss
yyyy format I'm made to wonder where came from.

Then the OP's choice should be 'strftime'. And that, too, can be seen
and
learned _about_ from TFM.

Maybe it's easy to find stuff in _T_FM, but not so easy to find stuff in
the OP's particular FM.


How the F do *you* know that? Are you the OP?

Never mind.

V
Jul 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.