I made a daemon that it is started by systemd, and inside my daemon I have a python function to get the time. The problem is that the time is wrong, I have 8 hours of difference.

This is my service script:

Description=auto-sync daemon

ExecStart=/bin/bash -c "/usr/bin/auto-sync -s"


I've tried multiple ways of getting the hour in python but they are all wrong.

from datetime import datetime
datetime.now().strftime("%d-%m-%Y %H:%M:%S")

I told my self that the problem could be the fact that some weird system user is running the script, so I added: User=root but I still having the same problem! Any Idea?

I actually didn't wanted to add +8 hours because I'm not sure if all the users of my program have the same problem


Is your timezone 8 hours off from GMT? It sounds like your python call to datetime.now() is not using your current timezone and is instead returning you the time it is in the GMT timezone.

Internally this time is just a long integer containing the number of seconds since Jan 1, 1970 GMT. Your python is running in the wrong timezone is the problem. You can use the pytz library to fix this, see these answers .

  • I haven't try pytz, but when I get the time with my root account or with an user account the time it is fine. Is that normal? – rsm Jun 2 '15 at 21:30
  • As a side note, systemd requires your clock set to UTC then adds or subtracts your timezone difference. – eyoung100 Jun 2 '15 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.