user3848207 user3848207 - 2 months ago 12
Python Question

Get local time reflected on PC and not other time zone

I am using python v3.6 to get current time.

import time
current_time = time.strftime("%H:%M:%S %Y-%m-%d", time.gmtime())


The code works but the time retrieved is from some other time zones. How do I retrieve time that is the same as reflected on the Windows 10 clock on my PC?

Answer Source

Try the below. I expect gmtime is for GMT(UTC more likely), vs local. See https://docs.python.org/2/library/time.html

    >>> time.strftime("%H:%M:%S %Y-%m-%d", time.gmtime())
    '03:16:00 2017-08-20'
    >>> time.strftime("%H:%M:%S %Y-%m-%d", time.localtime())
    '13:16:08 2017-08-20