# Time::getCurrentTime() returning current system time?

**URL:** <https://forum.juce.com/t/time-getcurrenttime-returning-current-system-time/8169>\
**Category:** General JUCE discussion\
**Created:** [February 21, 2012, 10:45am UTC](https://forum.juce.com/t/time-getcurrenttime-returning-current-system-time/8169 "2012-02-21T10:45:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![acn](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@acn](https://forum.juce.com/u/acn)\
**Post date:** [February 21, 2012, 10:45am UTC](https://forum.juce.com/t/time-getcurrenttime-returning-current-system-time/8169/1 "2012-02-21T10:45:14Z")

</div>

Hello All,  
I’ve a very basic scenario in which I need the exact system time… Also juce::Time is giving me the proper output throughout the life of the app… But I’ve observed the case that if I update my system time manually and then check my Time::getCurrentTime() then I am still getting the previous time value… Can someone help me to get the updated value… Thanks so much…

---

<div class="post-metadata">

**Author:** ![jfitzpat](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@jfitzpat](https://forum.juce.com/u/jfitzpat)\
**Post date:** [October 12, 2012, 2:48pm UTC](https://forum.juce.com/t/time-getcurrenttime-returning-current-system-time/8169/2 "2012-10-12T14:48:59Z")

</div>

FWIW, I believe that the issue is the implementation of getCurrentTime().

It appears that getCurrentTime calls currentTimeMillis(). That call only gets the system time initially, or when the static counter wraps.

---

<div class="post-metadata">

**Author:** ![acn](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@acn](https://forum.juce.com/u/acn)\
**Post date:** [October 15, 2012, 7:32am UTC](https://forum.juce.com/t/time-getcurrenttime-returning-current-system-time/8169/3 "2012-10-15T07:32:46Z")

</div>

Yup you are right, thanks for your views… I think that’s the scenario… Its not updated once my system is up and running… Do you find any solution for this…?

---

<div class="post-metadata">

**Author:** ![jfitzpat](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@jfitzpat](https://forum.juce.com/u/jfitzpat)\
**Post date:** [October 15, 2012, 8:29pm UTC](https://forum.juce.com/t/time-getcurrenttime-returning-current-system-time/8169/4 "2012-10-15T20:29:38Z")

</div>

As a workaround, I made my own getSystemTime() call. It is essentially the guts of the millis call used in the Time class, without the ‘- now’ conversion to an ‘offset’.

I then pass in that result, which is an int64 of mS since the epoch, to one of the Time constructors, so I can use all the normal time methods.

But I reported the issue to Jules, since there are other ramifications (ex. when the computer goes to sleep, the mS timer can stop), so I’m sure he’ll update the Time class eventually.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [October 15, 2012, 9:37pm UTC](https://forum.juce.com/t/time-getcurrenttime-returning-current-system-time/8169/5 "2012-10-15T21:37:45Z")

</div>

Thanks guys, I know about this - will get it sorted within the next couple of days…

---

<div class="post-metadata">

**Author:** ![acn](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@acn](https://forum.juce.com/u/acn)\
**Post date:** [October 25, 2012, 7:36am UTC](https://forum.juce.com/t/time-getcurrenttime-returning-current-system-time/8169/6 "2012-10-25T07:36:45Z")

</div>

Thanks so much jfitzpat & jules… I really appreciate the help…

---

<div class="post-metadata">

**Author:** ![X-Ryl669](https://avatars.discourse-cdn.com/v4/letter/x/a5b964/32.png) [@X-Ryl669](https://forum.juce.com/u/X-Ryl669)\
**Post date:** [October 26, 2012, 1:19pm UTC](https://forum.juce.com/t/time-getcurrenttime-returning-current-system-time/8169/7 "2012-10-26T13:19:24Z")

</div>

The thing is that Time and Clock are totally different concept, and often overlooked by library programmer.  
A clock is something that increase linearly, whatever the state of the computer, the face of the moon etc… It doesn’t jump back (never ever). And whatever the state when you call it, it’s guarranted that int a = getClock(), b = getClock() =\> b \> a. (think of a multithreaded program running on different core)

A time is something that can jiggle, go back, be offset anytime. It’s sometime, we, human make sense of it.

When you need a time to measure something, you actually need a clock (typically using clock\_gettime(CLOCK\_MONOTONIC) under linux).  
When you need to display/parse something coming from the user, you need a time (typically using clock\_gettime(CLOCK\_REALTIME) under linux).

Currently, Juce implementation of Time is mixing the concepts too.
