![]() |
| | #1 |
| Registered User Join Date: Jan 2008
Posts: 8
| I've searched the topic on google and this website, but i could not find the exact answer what i was looking for. For a certain scenario in my application (timestamps related) i need time in milliseconds. What i am currently doing is to get time in seconds using time() function and convert it into milliseconds by multiplying it with 1000. But the problem is that time_t is signed long (32 bit). When i multiply time_in_seconds with 1000, it overflows 32 bits and the resulting time in milliseconds becomes -ve. Please tell me how can i get time in milliseconds ? Also, i don't want processor time taken, i want wallclock time. OS: Unix Thanx |
| coder_009 is offline | |
| | #2 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| If you only need time(), then cast it to unsigned long long, then multiply it by 1000. That way it won't overflow. But... it seems you might need more precision if you're targeting milliseconds...
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #3 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Perhaps you can use long-long. In at least Linux, you have gettimeofday - it may exist in other Unix variants too. It gives you time in microseconds (although it may jump in steps of several microseconds at a time). -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #4 |
| Registered User Join Date: Jan 2008
Posts: 8
| Isn't there any function on Unix or Linux that gives time from start of the process rather than the epoch? Such a long time period from 1970 to now makes it so big in magnitude. |
| coder_009 is offline | |
| | #5 | |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Quote:
-- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. | |
| matsp is offline | |
![]() |
| Tags |
| milliseconds, time, unix |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Execution Time - Rijandael encryption | gamer4life687 | C++ Programming | 5 | 09-20-2008 09:25 PM |
| Sending an email in C program | Moony | C Programming | 28 | 10-19-2006 10:42 AM |
| Journey time prog 1 minute wrong | mike_g | C Programming | 4 | 10-12-2006 03:41 AM |
| time class | Unregistered | C++ Programming | 1 | 12-11-2001 10:12 PM |