473,395 Members | 1,401 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,395 software developers and data experts.

time_t in seconds

i've read recently that time_t doesn't have to be in second resolution
but if it isn't, then what resolution could it be in?

microseconds, milliseconds, are all valid?

also, does anyone know of an implementation
that does not use second resolution for a time_t?
Nov 14 '05 #1
6 7839
j0mbolar wrote:
i've read recently that time_t doesn't have to be in second resolution
but if it isn't, then what resolution could it be in?

microseconds, milliseconds, are all valid?


It doesn't have to even be a linear metric.

Nov 14 '05 #2
>i've read recently that time_t doesn't have to be in second resolution
but if it isn't, then what resolution could it be in?
time_t is not required to be represented as a number of <time unit>
since <epoch>. That said, if it IS represented as a number of <time
unit> since <epoch>, any time unit, regardless of how silly, and
any epoch is acceptable. It is a quality-of-implementation issue
that times near to now should be representable, and with fairly
decent resolution (an 8-bit integer counter of geologic ages would
be considered poor here, as would a 32-bit number of picoseconds
since the beginning of the universe. Putting the epoch at the END
of the universe is also problematical since I don't think anyone
knows when that is relative to now. The same applies to putting
it as the day of the assassination of World President Saddam Hussein).

One possible representation of time_t is:
hhHHSSMMmmddyyyy
substitute decimal digits for the values, then treat it as a decimal
integer. A time_t needs more than 48 bits for this representation.
yyyy = year (Y10K problem here!!)
mm = month (1-12)
dd = day of month (1-31)
HH = hour (0-24)[*]
MM = minute (0-60)[*]
SS = second (0-60)[*]
hh = hundredths of seconds (0-99)
[*] Some of these limits may seem a bit strange to allow for
leap seconds.

Note that the fields are put in a decidedly non-endian order, so
the result you get from adding or subtracting them is essentially
useless, and even comparing them as integers doesn't tell you which
comes first unless they happen to both be in the same second.
microseconds, milliseconds, are all valid?
Yes, as are nano-fortnights and a big integer type that packs the
28 characters of "Sat Apr 17 19:58:47 CDT 2004" into it.
also, does anyone know of an implementation
that does not use second resolution for a time_t?


Microsoft systems such as MS-DOS used a bitfield representation of
year, month, day, hour, minute, and seconds for file date
representations. I don't think they used it as a time_t, though.
BSD Unix systems also have a struct timeval which typically contains
a time_t and a counter for fractions of seconds. That also isn't
actually used as a time_t.

Gordon L. Burditt
Nov 14 '05 #3
go***********@burditt.org.org (Gordon Burditt) writes:
[...]
One possible representation of time_t is:
hhHHSSMMmmddyyyy
substitute decimal digits for the values, then treat it as a decimal
integer. A time_t needs more than 48 bits for this representation.
yyyy = year (Y10K problem here!!)
mm = month (1-12)
dd = day of month (1-31)
HH = hour (0-24)[*]
MM = minute (0-60)[*]
SS = second (0-60)[*]
hh = hundredths of seconds (0-99)

[*] Some of these limits may seem a bit strange to allow for
leap seconds.


Small quibble: to allow for leap seconds, it's sufficient to make the
range of SS 0-60; MM can be 0-59, and HH can be 0-23.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #4
"Gordon Burditt" <go***********@burditt.org.org> wrote:
One possible representation of time_t is:
hhHHSSMMmmddyyyy
substitute decimal digits for the values, then treat it as a decimal
integer. A time_t needs more than 48 bits for this representation.
yyyy = year (Y10K problem here!!)
mm = month (1-12)
dd = day of month (1-31)
HH = hour (0-24)[*]
MM = minute (0-60)[*]
SS = second (0-60)[*]
hh = hundredths of seconds (0-99)


typedef long long time_t;

double difftime(time_t a, time_t b)
{
double year = (a % 10000
- b % 10000) * 31556952.0;
double month = (a % 100000000 / 1000000
- b % 100000000 / 1000000) * 2629746.0;
double day = (a % 1000000 / 10000
- b % 1000000 / 10000) * 86400.0;
double hour = (a % 100000000000000 / 1000000000000
- b % 100000000000000 / 1000000000000) * 3600.0;
double minute = (a % 10000000000 / 100000000
- b % 10000000000 / 100000000) * 60.0;
double second = (a % 1000000000000 / 10000000000
- b % 1000000000000 / 10000000000);
double hundredth = (a / 100000000000000
- b / 100000000000000) / 100.0;
return year + month + day + hour + minute + second + hundredth;
}

The values for month and year are for an average year, but they should
actually depend on the year in question. Argh!

--
Simon.
Nov 14 '05 #5
"Gordon Burditt" <go***********@burditt.org.org> wrote:
One possible representation of time_t is:
hhHHSSMMmmddyyyy .... yyyy = year (Y10K problem here!!)
mm = month (1-12)
dd = day of month (1-31)
HH = hour (0-24)[*]
MM = minute (0-60)[*]
SS = second (0-60)[*]
hh = hundredths of seconds (0-99) .... Note that the fields are put in a decidedly non-endian order


Isn't there a precedent for this representation already? :-)
microseconds, milliseconds, are all valid?


Yes, as are nano-fortnights and a big integer type that packs the
28 characters of "Sat Apr 17 19:58:47 CDT 2004" into it.


A colleague of mine has had a teacher of physics who insisted on
converting everything to elementary units.

Stones, furlongs and fortnights.

Peter
Nov 14 '05 #6
In <2d**************************@posting.google.com > j0******@engineer.com (j0mbolar) writes:
also, does anyone know of an implementation
that does not use second resolution for a time_t?


I have yet to hear about one. I guess there was far too much existing
practice in having time_t as a second offset from one epoch or another
(the MSDOS epoch used to be 1980.1.1 on the early implementations, IIRC)
that no one (or practically no one) bothered to reinvent this wheel.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #7

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

Similar topics

1
by: Anand CS | last post by:
Hi All I have question regarding time data structures... I have 64 bit unsigned microsecond resolution (unsigned __int64 for windows/and unsigned long long for others) variable. It stores the...
1
by: Tomas Deman | last post by:
Hi all, I have a problem converting a borland cpp (v4.52) time_t value to a visual basic date. What does borland exactly store? I heard this should be #seconds since 1/1/1970 0:00 in EST time....
8
by: Ian Pilcher | last post by:
When adding two values of type time_t, how can I check for overflow? Maybe I'm just brain-cramped today, but I can't figure out how to do it. Thanks! --...
7
by: John J. Hughes II | last post by:
Is there a better way of doing this? DateTime startTime = new DateTime(1970,1,1,0,0,0,0); TimeSpan currTime = DateTime.Now - startTime; UInt32 time_t =...
2
by: Mark | last post by:
Hi.. I'm writing a web service in C# and needs to produce some time_t values in the xml output, and near as I can figure there appears to be a bug in the C# datetime arithmetic. Below is an...
45
by: loudking | last post by:
Hello, all I don't quite understand what does ((time_t)-1) mean when I execute "man 2 time" RETURN VALUE On success, the value of time in seconds since the Epoch is retu rned. On error,...
1
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, In MSDN for time function, time_t time( time_t *timer ); http://msdn2.microsoft.com/en-us/library/1f4c8f33(VS.80).aspx
8
by: Abubakar | last post by:
Hi, Lets say I have three integers (date, month, and year) as part of a struct lets say like struct mydate{ int day, month, year}; I want to add x number of days to this date. And it should be a...
4
by: Mike Copeland | last post by:
How do I mask out all but the _time_ components of a time_t value? Specifically, I have the following: time_t wTime = 1226764757; I happen to know that this is November 16, 2008 @ 8:59:17, but I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.