473,686 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

time

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
5 2056
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2950
by: Bart Nessux | last post by:
am I doing this wrong: print (time.time() / 60) / 60 #time.time has been running for many hours if time.time() was (21600/60) then that would equal 360/60 which would be 6, but I'm not getting 6 so I'm not doing the division right, any tips?
5
3647
by: David Stockwell | last post by:
I'm sure this has been asked before, but I wasn't able to find it. First off I know u can't change a tuple but if I wanted to increment a time tuple by one day what is the standard method to do that? I've tried the obvious things and haven't gotten very far. I have a time tuple that was created like this: aDate = '19920228' x = time.strptime(aDate,"%Y%m%d")
6
12926
by: David Graham | last post by:
Hi I have asked this question in alt.php as the time() function as used in setcookie belongs to php - or does it belong equally in the javascript camp - bit confused about that. Anyway, can anyone here put me straight on the following: I had a look at the time() function came across this: "To clarify, it seems this function returns the time of the computer's clock and does not do any timezone adjustments to return GMT, so you are...
3
3148
by: Szabolcs Nagy | last post by:
I have to measure the time of a while loop, but with time.clock i always get 0.0s, although python manual sais: "this is the function to use for benchmarking Python or timing algorithms" So i tested timer functions capabilities with a short script: import time import os
6
2850
by: Rebecca Smith | last post by:
Today’s question involves two time text boxes each set to a different time zone. Initially txtCurrentTime will be set to Pacific Time or system time. This will change with system time as we travel across the country. txtRaceTime will always be set to Central Time regardless of where we are in the US. At first I tried ‘Now() – “xx:xx:xx” but that produced an error. Anyway as we approach the east coast the ‘minus’ would need to be a...
3
2714
by: luscus | last post by:
Thanks for all the responses on my first question. Unfortunately the answers I was given were too complicated for my small brain , and neophite condition to understand. So if you could talk down to me and write in easier terms I would be very gratefull to all you access wizards! Here is my problem. I have a table with maybe 10 fields, It is used to imput information taken over the phone to solve patient problems in our Spanish...
3
2028
by: cj | last post by:
If I want to check to see if it's after "11:36 pm" what would I write? I'm sure it's easy but I'm getting tired of having to work with dates and times. Sometimes I just want time or date. And to be able to do comparisons on them.
1
14591
by: davelist | last post by:
I'm guessing there is an easy way to do this but I keep going around in circles in the documentation. I have a time stamp that looks like this (corresponding to UTC time): start_time = '2007-03-13T15:00:00Z' I want to convert it to my local time. start_time = time.mktime(time.strptime(start_time, '%Y-%m-%dT%H:%M:
2
19578
by: Roseanne | last post by:
We are experiencing very slow response time in our web app. We run IIS 6 - windows 2003. I ran iisstate. Here's what I got. Any ideas?? Opened log file 'F:\iisstate\output\IISState-812.log' *********************** Starting new log output
9
8290
by: Ron Adam | last post by:
I'm having some cross platform issues with timing loops. It seems time.time is better for some computers/platforms and time.clock others, but it's not always clear which, so I came up with the following to try to determine which. import time # Determine if time.time is better than time.clock # The one with better resolution should be lower.
0
8586
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9057
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8941
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8781
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7606
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6443
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5801
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2955
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.