473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Question on epoch time

Is the epoch time the number of seconds elapsed since January 1st 1970
in my timezone or as per UTC? I mean, if A's program makes a call to
time() in Melboune and B's program makes a call to time() in Montreal
AT THIS VERY INSTANT, will they return the same values, or will A's
program return a value that is more than B's value by 36000 (since
Melboune is 10 hours ahead of Montreal).

Thanks,
Anil

Jul 20 '07 #1
11 3660
On Jul 20, 2:48 pm, use...@sta.samsung.com wrote:
Is the epoch time the number of seconds elapsed since January 1st 1970
in my timezone or as per UTC? I mean, if A's program makes a call to
time() in Melboune and B's program makes a call to time() in Montreal
AT THIS VERY INSTANT, will they return the same values, or will A's
program return a value that is more than B's value by 36000 (since
Melboune is 10 hours ahead of Montreal).

Thanks,
Anil

Sorry, I meant 14 hours ahead.

Jul 20 '07 #2
<us****@sta.samsung.comwrote in message
news:11**********************@n2g2000hse.googlegro ups.com...
Is the epoch time the number of seconds elapsed since January 1st 1970
in my timezone or as per UTC? I mean, if A's program makes a call to
time() in Melboune and B's program makes a call to time() in Montreal
AT THIS VERY INSTANT, will they return the same values, or will A's
program return a value that is more than B's value by 36000 (since
Melboune is 10 hours ahead of Montreal).
<OT>
It depends, since that's implementation-specific.

The POSIX epoch is defined as 1 Jan 1970 00:00:00 UTC. That's why folks in
the Western Hemisphere occasionally see dates of 31 Dec 1969 in odd places.

The DOS/Windows epoch is, IIRC, 1 Jan 1980 00:00:00 in the local timezone.
</OT>

Relying on there even _being_ an epoch, or that a time_t looks anything like
you expect, is unportable.

S

--
Stephen Sprunk "Those people who think they know everything
CCIE #3723 are a great annoyance to those of us who do."
K5SSS --Isaac Asimov
--
Posted via a free Usenet account from http://www.teranews.com

Jul 20 '07 #3
us****@sta.samsung.com wrote:
Is the epoch time the number of seconds elapsed since January 1st 1970
in my timezone or as per UTC? I mean, if A's program makes a call to
time() in Melboune and B's program makes a call to time() in Montreal
AT THIS VERY INSTANT, will they return the same values, or will A's
program return a value that is more than B's value by 36000 (since
Melboune is 10 hours ahead of Montreal).
http://en.wikipedia.org/wiki/Epoch_(reference_date)
http://en.wikipedia.org/wiki/Unix_time

Pretty complete overview, along with the historical oddities. How
humans compute with time values is an interesting problem to solve
sometimes.
--
clvrmnky <mailto:sp******@clevermonkey.org>

Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
Jul 20 '07 #4
us****@sta.samsung.com wrote:
>
Is the epoch time the number of seconds elapsed since January 1st 1970
in my timezone or as per UTC?
It's not specified by the C standard, but POSIX defines it to be per
UTC.

-Larry Jones

Some people just don't have inquisitive minds. -- Calvin
Jul 20 '07 #5
On Jul 20, 10:12 pm, "Stephen Sprunk" <step...@sprunk.orgwrote:

[I know that this is off-topic, but...]
The POSIX epoch is defined as 1 Jan 1970 00:00:00 UTC.
Where? I'd always believed that it was implementation defined,
but that time_t was required to contain seconds from some epoch,
but I can't find even that in the on line copy of the Posix
standard.

(It worries me, because I regularly use t1-t2 to get the elapsed
time in seconds, instead of difftime(), when portability is
limited to Unix. And now I learn that even that isn't
portable.)
Relying on there even _being_ an epoch, or that a time_t looks
anything like you expect, is unportable.
So it would seem. For a very large definition of "portable".
(Code that is only portable to Posix compliant C++ compilers is
still "portable". But apparently, this doesn't work even there.)

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 22 '07 #6
On Jul 20, 10:50 pm, lawrence.jo...@ugs.com wrote:
use...@sta.samsung.com wrote:
Is the epoch time the number of seconds elapsed since January 1st 1970
in my timezone or as per UTC?
It's not specified by the C standard, but POSIX defines it to be per
UTC.
Since you're the real expert here: where? In
http://www.mail-archive.com/le******.../msg00109.html,
Landon Curt Noll describes what I had always believed to be the
case. (I didn't think that the epoch was fixed, but I definitly
recall the discussions concerning the handling of leap seconds.)
But I simply cannot find it in the on-line Posix standard; in
fact, I find a definite statement that "time_t and clock_t shall
be integer or real-floating types".

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 22 '07 #7
On Jul 20, 11:02 pm, Clever Monkey <spamt...@clevermonkey.org.INVALID>
wrote:
use...@sta.samsung.com wrote:
Is the epoch time the number of seconds elapsed since January 1st 1970
in my timezone or as per UTC? I mean, if A's program makes a call to
time() in Melboune and B's program makes a call to time() in Montreal
AT THIS VERY INSTANT, will they return the same values, or will A's
program return a value that is more than B's value by 36000 (since
Melboune is 10 hours ahead of Montreal).
http://en.wikipedia.org/wiki/Epoch_(...wiki/Unix_time
Pretty complete overview, along with the historical oddities. How
humans compute with time values is an interesting problem to solve
sometimes.
Regretfully, the articles just repeat common knowledge, without
citing any real sources, so they don't mean anything. (All too
typical of Wikipedia, I fear.)

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 22 '07 #8
James Kanze wrote:
On Jul 20, 10:50 pm, lawrence.jo...@ugs.com wrote:
>use...@sta.samsung.com wrote:
Is the epoch time the number of seconds elapsed since January 1st 1970
in my timezone or as per UTC?
>It's not specified by the C standard, but POSIX defines it to be per
UTC.

Since you're the real expert here: where?
I would think you find it in Section 4.14 [Seconds Since the Epoch]. See

http://www.opengroup.org/onlinepubs/009695399/
Best

Kai-Uwe Bux
Jul 22 '07 #9
On Jul 22, 2:21 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
James Kanze wrote:
On Jul 20, 10:50 pm, lawrence.jo...@ugs.com wrote:
use...@sta.samsung.com wrote:
Is the epoch time the number of seconds elapsed since January 1st 1970
in my timezone or as per UTC?
It's not specified by the C standard, but POSIX defines it to be per
UTC.
Since you're the real expert here: where?
I would think you find it in Section 4.14 [Seconds Since the Epoch]. See
http://www.opengroup.org/onlinepubs/009695399/
Interesting. Now if there is only some text to somehow relate
time_t to "Seconds Since the Epoch". (The section you mention
doesn't mention time_t at all.)

I'd only looked for the definition of time_t itself before. A
quick search for "epoch" also turns up the specification for
mktime, where it says "The mktime() function shall convert the
broken-down time, expressed as local time, in the structure
pointed to by timeptr, into a time since the Epoch value with
the same encoding as that of the values returned by time()."
And I'm having a hard time figuring out what that is supposed to
mean (although the "with the same encoding as that of the values
returned by time()" certainly suggests that different encodings
are possible).

(Realistically, of course, any Unix system in which time_t was
not an integral value with the number of seconds since the
epoch, or at least since some epoch, would break so many
programs that it wouldn't be used. Or at least, I hope so,
since some of those programs would be my own:-).)

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 22 '07 #10
James Kanze <ja*********@gmail.comwrites:
On Jul 20, 10:12 pm, "Stephen Sprunk" <step...@sprunk.orgwrote:
[I know that this is off-topic, but...]
>The POSIX epoch is defined as 1 Jan 1970 00:00:00 UTC.

Where? I'd always believed that it was implementation defined,
but that time_t was required to contain seconds from some epoch,
but I can't find even that in the on line copy of the Posix
standard.
[...]

I'm looking at www.opengroup.org.

The definition of time_t isn't very specific, but the definition of
the time() function says it returns "the value of time in seconds
since the Epoch". The "Epoch" is defined as "The time zero hours,
zero minutes, zero seconds, on January 1, 1970 Coordinated Universal
Time (UTC)."

(I think that UTC wasn't defined until some time after 1970, but I
suppose its definition can be applied retroactively.)

But time_t can be either an integer type (either signed or unsigned)
or a floating-point type.

To maintain some topicality for comp.lang.c, I'll mention (yet again)
that these requirements go beyond what's required by the C standard.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 22 '07 #11
On Jul 22, 10:56 pm, Keith Thompson <ks...@mib.orgwrote:
James Kanze <james.ka...@gmail.comwrites:
On Jul 20, 10:12 pm, "Stephen Sprunk" <step...@sprunk.orgwrote:
[I know that this is off-topic, but...]
The POSIX epoch is defined as 1 Jan 1970 00:00:00 UTC.
Where? I'd always believed that it was implementation defined,
but that time_t was required to contain seconds from some epoch,
but I can't find even that in the on line copy of the Posix
standard.
[...]
I'm looking atwww.opengroup.org.
That's my usual source too.
The definition of time_t isn't very specific,
That's putting it mildly:-).
but the definition of
the time() function says it returns "the value of time in seconds
since the Epoch".
So my next question is why this page didn't turn up when I
searched for "epoch" or "Epoch" at the site:-). The only page
which did show up was mktime, and that speaks of an "encoding"
for time_t.

My impression is that Posix is rather ambiguous here. I do wish
it would say somewhere that whatever the type, the actual
numeric value in the time_t is the seconds from the epoch.
That's sort of implicit in things like the above---otherwise,
what does "the value of time in seconds since the Epoch" mean?
But if that's the case, why don't the requirements for time_t
say so, and why does the specification of mktime use language
like "with the same encoding as that of the values returned by
time()"?
The "Epoch" is defined as "The time zero hours,
zero minutes, zero seconds, on January 1, 1970 Coordinated Universal
Time (UTC)."
(I think that UTC wasn't defined until some time after 1970, but I
suppose its definition can be applied retroactively.)
It's a different issue, but §4.14 definitly says it is NOT UTC.
In particular, a Posix conformant implementation is required to
ignore leap seconds (except, of course, that there are no fixed
requirements on the accuracy of the clock, so presumably, a
Posix conformant implementation could arrange things so the
clock "just happened" to be off by the amount necessary to take
into account leap seconds).
But time_t can be either an integer type (either signed or
unsigned) or a floating-point type.
But if I take the difference between two type_t, I'll get a
type_t with the number of seconds between the two times. That,
at least, is what I'm looking for; I've always assumed that this
works in a Posix conformant environment (and under more recent
Windows), but I'm have great difficulty finding such a guarantee
in the standard.
To maintain some topicality for comp.lang.c, I'll mention (yet
again) that these requirements go beyond what's required by
the C standard.
Definitly.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 23 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mark | last post by:
I want to simply get the unix style epoch time (number of secs to now from Jan 01, 1970 UTC) for use as a timestamp to track the staleness of some objects. So I don't care about time zones or...
5
by: Grey Alien | last post by:
I need to convert timestamps that are given as the number of seconds that have elapsed since midnight UTC of January 1, 1970, (not counting leap seconds). It seems all of the std C functions...
11
by: usenet | last post by:
Is the epoch time the number of seconds elapsed since January 1st 1970 in my timezone or as per UTC? I mean, if A's program makes a call to time() in Melboune and B's program makes a call to...
2
by: Richard Rossel | last post by:
Hi friends, I need a little help here, I 'm stuck with epoch calculation issue. I have this datetime: date_new = datetime(*time.strptime('20080101T000000','%Y%m%dT%H%M%S') ) This date_new is in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...

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.