0
Making a system time to GMT+3
from datetime import datetime from itertools import cycle now = datetime.now() hour = str(now.hour).zfill(2) minute = str(now.minute).zfill(2) second = str(now.second).zfill(2) ptime = cycle(hour + minute + second) print(f'System time: {hour}:{minute}:{second}') How can I make the clock to GMT +3 Hours
3 RĂ©ponses
+ 5
from datetime import datetime, timezone, timedelta
from itertools import cycle
import pytz
now = datetime.now(timezone(timedelta(hours=+3)))
hour = str(now.hour).zfill(2)
minute = str(now.minute).zfill(2)
second = str(now.second).zfill(2)
ptime = cycle(hour + minute + second)
print(f'System time: {hour}:{minute}:{second}')
+ 3
Rather than zero-filling the individual time components, it is much more simple to use a format mask.
print(now.strftime('%H:%M:%S'))
+ 2
Hey, it is exactly my code.
https://sololearn.com/compiler-playground/cJT3A3qAUMhR/?ref=app
I opted not to play with the timezone because it requires user input before running it in playground, and the input prompt doesn't display to the user.
You can copy the code to a .py file in your conputer.
Run the code in your own device, it will get the time from it.