473,503 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there an inverse of gmtime()?


Is there a portable way to convert between a struct tm and a time_t, for UTC?

I know that time_t is seconds since the epoch (1970-01-01T00:00:00Z).

Now, you can convert a time_t to a struct tm for either local (localtime()) or UTC (gmtime()).
But the reverse operation (mktime()) only converts a local time, as far as I can tell. What I'm
looking for is a portable way to convert a struct tm holding a UTC value into a time_t.

I'm currently using an OS specific kludge which involves setting the TZ environment variable, and
I know this is highly non-portable. Anybody got a better idea?

Thanks

Jul 19 '05 #1
2 9509
On Wed, 22 Oct 2003 16:23:26 GMT, red floyd <no*****@here.dude> wrote:

Is there a portable way to convert between a struct tm and a time_t, for
UTC?

I know that time_t is seconds since the epoch (1970-01-01T00:00:00Z).

Now, you can convert a time_t to a struct tm for either local
(localtime()) or UTC (gmtime()).
But the reverse operation (mktime()) only converts a local time, as far
as I can tell. What I'm
looking for is a portable way to convert a struct tm holding a UTC value
into a time_t.
That means that time_t holds the value in the 0Z.
Now if you will do this you will have time_t in your zone ?

I'm currently using an OS specific kludge which involves setting the TZ
environment variable, and
I know this is highly non-portable. Anybody got a better idea?
Calculate the difference between gmtime(time_t) and localtime(time_t).
This is portable.


Thanks

You are welcome.

--
grzegorz
Jul 19 '05 #2
gr**********@pacbell.net wrote:
On Wed, 22 Oct 2003 16:23:26 GMT, red floyd <no*****@here.dude> wrote:

Is there a portable way to convert between a struct tm and a time_t,
for UTC?

[long winded question redacted]


Calculate the difference between gmtime(time_t) and localtime(time_t).
This is portable.


Duh! [slaps forehead] I should have thought of that one!

Thanks again!

Jul 19 '05 #3

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

Similar topics

6
7342
by: David C. Fox | last post by:
Is there a function which takes a list of tuples and returns a list of lists made up of the first element of each tuple, the second element of each tuple, etc.? In other words, the the inverse...
0
1493
by: John Hunter | last post by:
I have a python2.3 datetime instance and a tzinfo instance (eg Eastern from the python library reference). What is the best way to convert that datetime instance to seconds since the epoch,...
1
3962
by: Florian Lindner | last post by:
Hello, I want to know if a certain duration is over. I try it like this with timedelta objects: d = datetime.timedelta(minutes = 2) t = time.gmtime() print (t + d < time.gmtime()) gives:
6
25187
by: vishnu mahendra | last post by:
hello to all, can any one please give me an algorithm to find inverse of a matrix of order n rows and m columns. thank you in advance, vishnu.
1
24510
by: KW | last post by:
Hi all, Appreciate if someone can help me out on this. Currently, I have a tm structure holding information of the UTC time, which is very likely to be in the past, meaning not the current...
11
4933
by: red floyd | last post by:
I have a copy of the C++ standard. Unfortunately, I don't have a copy of the C89 standard, and the question I have is related to something incorporated by reference. Specifically, what does the...
3
7082
by: Smokey Grindle | last post by:
How can you "inverse" a color in GDI+? Say the color I have is blue, the inverse of that is yellow... how would you go about doing this? is there a simpler way then taking the RGB values and...
4
2089
by: Jonathan Fine | last post by:
Hello As part of the MathTran project I found myself wanting to maintain a bijection between long names and short names. http://www.open.ac.uk/mathtran In other words, I wanted to have two...
3
5191
by: jorba101 | last post by:
Following prototypes apply for localtime and gmtime: struct tm *localtime(const time_t *timer); struct tm *gmtime(const time_t *timer); I wonder, should I understand that localtime and...
0
7202
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
7280
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
7330
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
6991
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
7460
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
5578
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,...
0
4672
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...
0
1512
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 ...
1
736
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.