473,591 Members | 2,902 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7889
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:
hhHHSSMMmmddyyy y
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***********@b urditt.org.org (Gordon Burditt) writes:
[...]
One possible representation of time_t is:
hhHHSSMMmmddyyy y
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_Keit h) 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:
hhHHSSMMmmddyyy y
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:
hhHHSSMMmmddyyy y .... 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******@engine er.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
25562
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 microsoconds elapsed since the Epoch... I want to convert this time into a string form.... AFAIK normally the procedure from a time_t structure to string format is something like...convert time_ to struct tm using localtime method......
1
3138
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. How can borland do this in dos without having set the TZ environment variable? I'd like to know what borland stores... Thanks in advance,
8
4937
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! -- ======================================================================== Ian Pilcher i.pilcher@comcast.net ========================================================================
7
20457
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 = Convert.ToUInt32(Math.Abs(currTime.TotalSeconds)); Regards, John
2
2104
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 example in asp.net using the JScript Date object to demonstrate the bug. The net problem is that the number of seconds calculation ends up an hour off (an extra hour). If anyone can point out a better way to run the calculation I'd apprecitate it ...
45
9330
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, ((time_t)-1) is returned, and errno is set
1
1245
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
4159
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 real date calculation thing. Like if the date is 31st december 2008, when i add 1 to this, it should become 1st feb 2009. This of course may require converting the above struct values to some data type that crt's date functons can understand. I...
4
3493
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 have many other such items from which I want to use only the _time_ portion (e.g. 8:59:17). How do I eliminate the "date" portions of either the time_t value or the number I assign to it? TIA
0
7935
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
7871
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8236
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
8227
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
6642
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...
0
5400
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
3893
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2379
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
1
1467
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.