473,473 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Network time to C time

Network time uses 1900 as its base. The C time library uses 1970. I want to
convert a network time value to a C library time. I.e. I have to subtract
the number of seconds from 1900 to 1970. Is there any library function to do
this?

Thanks.

Nov 4 '07 #1
17 3746
Andrew Chalk wrote:
>
Network time uses 1900 as its base. The C time library uses 1970.
I want to convert a network time value to a C library time. I.e.
I have to subtract the number of seconds from 1900 to 1970. Is
there any library function to do this?
For heavens sake, why? That number is a constant. Just subtract
it. And all this is off-topic anyhow.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Nov 4 '07 #2
CBFalconer <cb********@yahoo.comwrites:
Andrew Chalk wrote:
>>
Network time uses 1900 as its base. The C time library uses 1970.
I want to convert a network time value to a C library time. I.e.
I have to subtract the number of seconds from 1900 to 1970. Is
there any library function to do this?

For heavens sake, why? That number is a constant. Just subtract
it. And all this is off-topic anyhow.
How the hell is asking about the existence for a C library function to
manipulate dates and times "Off Topic"?!?!?!?! Streuth.
>
--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.
Nov 4 '07 #3
CBFalconer said:
Andrew Chalk wrote:
>>
Network time uses 1900 as its base. The C time library uses 1970.
I want to convert a network time value to a C library time. I.e.
I have to subtract the number of seconds from 1900 to 1970. Is
there any library function to do this?

For heavens sake, why? That number is a constant. Just subtract
it.
Hardly a constant. Not all C libraries use 1970 as their base, so the
number of seconds between the network epoch and a C library epoch is in
fact not constant at all.
And all this is off-topic anyhow.
Why?

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 4 '07 #4
In article <47***************@yahoo.com>,
CBFalconer <cb********@maineline.netwrote:
>Andrew Chalk wrote:
>Network time uses 1900 as its base. The C time library uses 1970.
I want to convert a network time value to a C library time. I.e.
I have to subtract the number of seconds from 1900 to 1970. Is
there any library function to do this?
>For heavens sake, why? That number is a constant. Just subtract
it.
Having it as a library function would save questions about (e.g.,)
whether either (or both) libraries take leap-seconds into account.

Also, the number of seconds between 1900 and 1970 is not representable
in a signed long (just misses -- signed long gets you a little over
68 years). That implies that if network time is defined as an
unsigned long that it runs out before C time runs out; if it is defined
some other way then a straight-forward subtraction is not appropriate
in C89. (Possibly network time is defined as long long, but if so then
it wouldn't be representable in C89, which seems unlikely.)
--
"There are some ideas so wrong that only a very intelligent person
could believe in them." -- George Orwell
Nov 4 '07 #5
"Andrew Chalk" <ac****@magnacartasoftware.comwrites:
Network time uses 1900 as its base. The C time library uses 1970. I
want to convert a network time value to a C library time. I.e. I
have to subtract the number of seconds from 1900 to 1970. Is there
any library function to do this?
No, there's no standard library function to do this. There may well
be a non-standard function; a newsgroup that deals with your operating
system is likely to be more helpful.

Incidentally, standard C doesn't require time_t to represent seconds
since 1970, though that's the most common implementation.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 4 '07 #6
CBFalconer <cb********@yahoo.comwrites:
Andrew Chalk wrote:
>Network time uses 1900 as its base. The C time library uses 1970.
I want to convert a network time value to a C library time. I.e.
I have to subtract the number of seconds from 1900 to 1970. Is
there any library function to do this?

For heavens sake, why? That number is a constant. Just subtract
it. And all this is off-topic anyhow.
No, the question isn't off-topic (in comp.lang.c); the answer just
happens to be no.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 4 '07 #7
And that constant is, what?

"CBFalconer" <cb********@yahoo.comwrote in message
news:47***************@yahoo.com...
Andrew Chalk wrote:
>>
Network time uses 1900 as its base. The C time library uses 1970.
I want to convert a network time value to a C library time. I.e.
I have to subtract the number of seconds from 1900 to 1970. Is
there any library function to do this?

For heavens sake, why? That number is a constant. Just subtract
it. And all this is off-topic anyhow.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Nov 4 '07 #8
Andrew Chalk wrote:
Network time uses 1900 as its base. The C time library uses 1970. I want to
convert a network time value to a C library time. I.e. I have to subtract
the number of seconds from 1900 to 1970. Is there any library function to do
this?
You have received earlier comments that
1. the number of seconds is a constant so you can simply subtract it
2. the number of seconds is not constants, since different C
implementations use different starting points
3. you may need to consider leap seconds and might not be able to
represent the time in a single C89 variable

These are all valid comments, in general. The simple problem
description leaves details open to interpretation.

For a given pair of defined time scales, i.e., a particular network time
specification and a particular C library implementation which uses a
representation of number of elapsed seconds since a starting point,
there is likely a single value to can be used to convert one time scale
to another.

If you a writing a portable implementation for all Standard C
implementations, but a single network standard, you can convert the
network time to a struct tm representation of local time, then use
mktime() to obtain the time_t representation.

If it is important to accurately handle leap seconds, you need to
consult the specification for your network time representation and
verify that your target C libraries have adequate handling. For most
uses it doesn't matter.

--
Thad
Nov 4 '07 #9
"Andrew Chalk" <ac****@magnacartasoftware.comwrites:
"CBFalconer" <cb********@yahoo.comwrote in message
news:47***************@yahoo.com...
>Andrew Chalk wrote:
>>Network time uses 1900 as its base. The C time library uses 1970.
I want to convert a network time value to a C library time. I.e.
I have to subtract the number of seconds from 1900 to 1970. Is
there any library function to do this?

For heavens sake, why? That number is a constant. Just subtract
it. And all this is off-topic anyhow.
And that constant is, what?
Please don't top-post. Read the following:

http://www.caliburn.nl/topposting.html
http://www.cpax.org.uk/prg/writings/topposting.php

Please don't quote signatures (the stuff following the "-- " line)
unless you're actually commenting on them. More generally, when you
post a followup, retain just enough of the parent article so your
reply makes sense on its own.

I've corrected both here.

The number of seconds between midnight 1900-01-01 and midnight
1970-01-01 is 2208988800. (That ignores leap seconds, but many time
representations also ignore leap seconds, which weren't introduced
until 1972 anyway.)

Knowing that might or might not be helpful. Though the C standard
says remarkably little about how times are represented, many systems
use a 32-bit signed integer representing seconds since 1970-01-01;
some systems do the same thing, but with a 64-bit signed intger.
(Using 1970-01-01 is a Unix standard, not a C standard, but it's
spread to some other operating systems for compatibility reasons.)

The value 2208988800 is (barely) too large to be represented in a
32-bit signed integer. There are probably ways around that, but
they'll depend on exactly how your "network time" is represented.
Adding 1104494400 twice *might* be a solution.

It's very likely that there's already a function that will reliably
convert between "network time" and "Unix time". You should ask in
comp.unix.programmer rather than soliciting guesses in comp.lang.c.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 4 '07 #10
On Sun, 4 Nov 2007 09:59:38 -0600, "Andrew Chalk"
<ac****@magnacartasoftware.comwrote:
>Network time uses 1900 as its base. The C time library uses 1970. I want to
convert a network time value to a C library time. I.e. I have to subtract
the number of seconds from 1900 to 1970. Is there any library function to do
this?
While Unix may use 1970 as time 0, the standard does not require any
of the library functions to do so.

Furthermore, the representation of time is not required to be in
seconds. (For example, Excel uses a floating point value of days and
fractions thereof.)

You can compute the value you need using the difftime function.
Remove del for email
Nov 5 '07 #11
Barry Schwarz <sc******@doezl.netwrites:
On Sun, 4 Nov 2007 09:59:38 -0600, "Andrew Chalk"
<ac****@magnacartasoftware.comwrote:
>>Network time uses 1900 as its base. The C time library uses 1970. I want to
convert a network time value to a C library time. I.e. I have to subtract
the number of seconds from 1900 to 1970. Is there any library function to do
this?

While Unix may use 1970 as time 0, the standard does not require any
of the library functions to do so.

Furthermore, the representation of time is not required to be in
seconds. (For example, Excel uses a floating point value of days and
fractions thereof.)
True, though Excel's time representation presumably isn't time_t.
Probably Excel runs on a system where time_t represents seconds since
1970 (in the C implementation if not in the operating system), and it
defines its own internal type for representing dates and times. But
yes, a C implementation *could* define time_t as a floating-point type
representing days and fractions thereof.
You can compute the value you need using the difftime function.
Um, maybe. difftime() computes the difference between two time_t
values, yielding a double result. But there's no guarantee that
1900-01-01 00:00:00 can be represented as a time_t (and on many
systems it can't). For that matter, there's no guarantee that
1970-01-01 00:00:00 is within the range of time_t (though I suspect it
is under all existing implementations).

But the computation isn't difficult. It's 70 years of 365 days each,
each day being 86400 seconds (24 * 60 * 60), plus 17 leap days of
86400 seconds each (1900 was not a leap year).

I'm assuming that this "network time" uses 1900-01-01 as its epoch.
The OP just said 1900, and I've think I've heard of representations
that use 1900-03-01 or 1901-01-01 to avoid the leap year irregularity.
If the OP is referring to NTP, then yes, the epoch is 1900-01-01 (and
the representation, which uses 32 bits for the whole number of seconds
and 32-bits for the fraction, will wrap around in 2036).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 5 '07 #12
Keith Thompson wrote:
Barry Schwarz <sc******@doezl.netwrites:
>On Sun, 4 Nov 2007 09:59:38 -0600, "Andrew Chalk"
<ac****@magnacartasoftware.comwrote:
>>Network time uses 1900 as its base. The C time library uses 1970. I want to
convert a network time value to a C library time. I.e. I have to subtract
the number of seconds from 1900 to 1970. Is there any library function to do
this?
While Unix may use 1970 as time 0, the standard does not require any
of the library functions to do so.

Furthermore, the representation of time is not required to be in
seconds. (For example, Excel uses a floating point value of days and
fractions thereof.)

True, though Excel's time representation presumably isn't time_t.
Probably Excel runs on a system where time_t represents seconds since
1970 (in the C implementation if not in the operating system), and it
defines its own internal type for representing dates and times. But
yes, a C implementation *could* define time_t as a floating-point type
representing days and fractions thereof.
>You can compute the value you need using the difftime function.

Um, maybe. difftime() computes the difference between two time_t
values, yielding a double result. But there's no guarantee that
1900-01-01 00:00:00 can be represented as a time_t (and on many
systems it can't). For that matter, there's no guarantee that
1970-01-01 00:00:00 is within the range of time_t (though I suspect it
is under all existing implementations).

But the computation isn't difficult. It's 70 years of 365 days each,
each day being 86400 seconds (24 * 60 * 60), plus 17 leap days of
86400 seconds each (1900 was not a leap year).

I'm assuming that this "network time" uses 1900-01-01 as its epoch.
The OP just said 1900, and I've think I've heard of representations
that use 1900-03-01 or 1901-01-01 to avoid the leap year irregularity.
If the OP is referring to NTP, then yes, the epoch is 1900-01-01 (and
the representation, which uses 32 bits for the whole number of seconds
and 32-bits for the fraction, will wrap around in 2036).
The idea that seconds since 1970 will wrap in 2036 assumes an integer
and 31 bits, not 32. With 32 bits we can live into 2109.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 6 '07 #13
Joe Wright <jo********@comcast.netwrote:
Keith Thompson wrote:
I'm assuming that this "network time" uses 1900-01-01 as its epoch.
The OP just said 1900, and I've think I've heard of representations
that use 1900-03-01 or 1901-01-01 to avoid the leap year irregularity.
If the OP is referring to NTP, then yes, the epoch is 1900-01-01 (and
the representation, which uses 32 bits for the whole number of seconds
and 32-bits for the fraction, will wrap around in 2036).
The idea that seconds since 1970 will wrap in 2036 assumes an integer
and 31 bits, not 32. With 32 bits we can live into 2109.
No, it's NTP, with 32 bits unsigned, and hence 136.summat years, since
1900, which will overflow in 2036. As noted, BTW, in the relevant RFC.

Richard
Nov 6 '07 #14
Joe Wright <jo********@comcast.netwrites:
Keith Thompson wrote:
[...]
>If the OP is referring to NTP, then yes, the epoch is 1900-01-01 (and
the representation, which uses 32 bits for the whole number of seconds
and 32-bits for the fraction, will wrap around in 2036).
The idea that seconds since 1970 will wrap in 2036 assumes an integer
and 31 bits, not 32. With 32 bits we can live into 2109.
NTP uses a 32-bit unsigned integer to represent seconds since 1900
(plus another 32 bits to represent fractional seconds); this wraps
around in 2036. Many Unix-like systems use a 32-bit signed integer to
represent seconds since 1970; this overflows in 2038.

For Unix-like systems, switching from 32-bit signed to 32-bit unsigned
would delay the overflow to 2106 (not 2109). However, both NTP and
Unix are migrating to 64 bits, so there's no need to use unsigned
integers and thereby lose the ability to represent dates before the
epoch.

These are, of course, just examples of possible representations for
time_t.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 6 '07 #15
CBFalconer <cb********@yahoo.comwrites:
Andrew Chalk wrote:
>>
Network time uses 1900 as its base. The C time library uses 1970.
I want to convert a network time value to a C library time. I.e.
I have to subtract the number of seconds from 1900 to 1970. Is
there any library function to do this?

For heavens sake, why? That number is a constant. Just subtract
it. And all this is off-topic anyhow.
Is it? Does it include, for example, leap seconds?

Chip

--
Charles M. "Chip" Coldwell
"Turn on, log in, tune out"
Somerville, Massachusetts, New England
Nov 6 '07 #16
Richard wrote:
....
Are leap seconds mentioned in the C-Standard? ...
In n1256.pdf, footnote 274 says "The range [0, 60] for tm_sec allows for
a positive leap second."
Nov 7 '07 #17
In article <1ViYi.20139$Rg1.12856@trnddc05>,
James Kuyper <ja*********@verizon.netwrote:
>Richard wrote:
...
>Are leap seconds mentioned in the C-Standard? ...

In n1256.pdf, footnote 274 says "The range [0, 60] for tm_sec allows for
a positive leap second."
Well, there ya go. We can talk about leap seconds here.
What a relief!

Nov 7 '07 #18

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

Similar topics

14
by: David W. Fenton | last post by:
I'm no stranger to this error message, but I have a client who is experiencing it, but, fortunately, without any actual data corruption, and it's driving them made. Their inability to grasp that...
5
by: Nirosh | last post by:
Hi All, Can any one suggest me a best way to do this .. I have a thrid party tool "EXE" that we need to use with our web service to manipulate some complex XML files, which reside in a...
4
by: Jeremy S. | last post by:
We're in the process of writing a new Windows Forms app and the desktop support folks want for it to be run from a network share. I know it's possible (i.e., just have the framework on the clients...
8
by: BJ | last post by:
Problem: How can I code up a client side process to detect if the network is available? Synopsis: I am writing ASP.NET input forms for a Panasonic Tuff book. The users will be walking around...
18
by: NEWSGROUPS | last post by:
I work for a large organization were my team has developed 2 very substantial databases in Access 2000. These databases have been working fine for the last 6 years with minimal issues or problems....
15
by: =?Utf-8?B?TVNU?= | last post by:
To demonstrate my problem, I have a very simple VB Windows application. It has a text box that is used to display a counter, a button to reset the counter, and a timer that increments the counter...
6
by: trytobreak | last post by:
Hi All, I am a network administrator in a fairly large software company and I would like to write myself a small utility, which would connect (one by one) to all machines on the network and get...
10
by: gary0gilbert | last post by:
An unusual spin to this recurring disk or network error in a Terminal Server environment. Access 2000, Terminal Server 2000, file server is windows 2000. All users have a separate copy of the...
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
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
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...
1
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...
0
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,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
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 ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.