469,160 Members | 1,853 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,160 developers. It's quick & easy.

converting to time_t

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......
as shown below..

time_t result;
result = time(NULL);
printf("%s\n", asctime(localtime(&result)));

But in my case I dont have a time_t structure as shown above but a
unsigned 64 bit value....How do I convert this to a time_t type
(portably) and use the same procedure shown above...

Any suggestions
Thanks
Senthil
Nov 13 '05 #1
1 22386
Anand CS wrote:
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......
as shown below..

time_t result;
result = time(NULL);
printf("%s\n", asctime(localtime(&result)));

But in my case I dont have a time_t structure as shown above but a
unsigned 64 bit value....How do I convert this to a time_t type
(portably) and use the same procedure shown above...

Any suggestions
Thanks
Senthil


time(null) returns the number of seconds since the epoch. The easiest thing
for you to do is something like:

uint64_t mytime;
time_t realtime;

mytime = getmytimefunc();
realtime = (time_t) (mytime / 1000000);
printf("%s\n", asctime(localtime(&result)));

Obviously it will loose the microsecond resolution.

Luke
Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by j0mbolar | last post: by
1 post views Thread by Tomas Deman | last post: by
7 posts views Thread by John J. Hughes II | last post: by
6 posts views Thread by minboymike | last post: by
7 posts views Thread by Angus Comber | last post: by
45 posts views Thread by loudking | last post: by
4 posts views Thread by PeteOlcott | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.