How to convert from time to UTC?

K

kackson

Hi.
I grabbed the date and time at compile time of my c++ codes. The
values returned are like

Aug 11 2004 and 12:30:04 .

I would like to convert these into UTC. Can this be done. I've
searched the net for hours but to my surprise, there dont seem to be a
simple function that can do such a conversion? I must be missing
something somewhere. Any pointers are appreciated. Thanks.
 
M

Marcelo

The "time" function returns the number of seconds elapsed since 00:00:00
Greenwich mean time (GMT), January 1, 1970, according to the system clock.
Then use "ctime" to convert the time_t returned value to a character string.
Well, I don't know if you are using __TIME__ to get the compile time, but I
think you can substitute this by some inline function using the time
functions above.
 
O

osmium

kackson said:
I grabbed the date and time at compile time of my c++ codes. The
values returned are like

Aug 11 2004 and 12:30:04 .

I would like to convert these into UTC. Can this be done. I've
searched the net for hours but to my surprise, there dont seem to be a
simple function that can do such a conversion? I must be missing
something somewhere. Any pointers are appreciated. Thanks.

I am confused by your question. You speak of "grabbing" the time and date
and these values being "returned". I am familiar with the process in the
preprocessor of *printing* the time and date but having the compiler return
these value to you sounds foreign. I have the impression that you want the
compiler to print UCT time but that isn't what I read. Do you care to
clarify? In the meantime, you might look at mktime() in <ctime> to see if
that is of any interest. Note that your post didn't address the daylight
saving time issue, so it may not be a completely definitive example.
 
J

Jack Klein

Please don't top post. Material you add in a reply belongs AFTER
quoted material you are commenting on, as I did below. There are
patches for Microsoft's boorish excuse for a virus catcher, er,
newsreader, to correct its ignorant default behavior of putting the
cursor at the top. Google for one and install it.
The "time" function returns the number of seconds elapsed since 00:00:00
Greenwich mean time (GMT), January 1, 1970, according to the system clock.

This is neither required nor guaranteed by C++. It happens to be true
on some systems, not true on others. C++ inherits its definition of
time_t and time() from ISO C. The only guarantee is that time_t is an
arithmetic type. Nothing is specified about its resolution or
interpretation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top