| Reference | Downloads | Github

Changing the clock from core.Clock to a Global Clock

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10):
PsychoPy version 2021.1.4
Standard Standalone? (y/n) y
What are you trying to achieve?:
Not so much a question about the builder in itself, but what I would like to do is change the clock. I’ve worked through many examples from the Psychopy Book and when I look at the onset/offset times they are in relation to the experiment start, not a global clock such as what time is it in the UK. e.g. lets say I have my Stroop task and it takes around a minute to complete. What I would like is the clock not to say InstrText.started = 14.1210222 in my CSV output, but rather InstrText.start = 14:02:36.565 for example.

I’ve had a google and look through the forums but it’s quite complex for me as a new user of Psychopy.

Does anyone know if there is a simple way to change the clock format?

Kind regards,


In a Builder experiment you can always use data.getDateStr() to get the time as a string, you can specify the format like so:


However this won’t be millisecond accurate - what you could do instead is import time (this is a builtin package so you won’t need to install it) and at the beginning of the experiment store time.time(), then you can add the time since experiment start to this value and convert it to local time format like this:

s = time.strftime("%H:%M:%S", time.gmtime(experimentStartTime + timeSince))  # Get formatted time to the second
ms = str(experimentStartTime + timeSince % 1)  # Get the millisecond value which was removed in this conversion
exactTime = s + "." + ms[2:]  # Add this millisecond value back in

Here’s an example:
showTime.psyexp (8.5 KB)

Hi Todd,

Thank you so much for the assistance, and also providing me with an example! I’ll try it out and let you know how I get on.

Kind regards,