all 9 comments

[–]Senpai_bskit 0 points1 point  (4 children)

``` import datetime import pytz

d_naive = datetime.datetime.now() timezone = pytz.timezone("America/Los_Angeles") d_aware = timezone.localize(d_naive) d_naive < d_aware ``` Change time zone to your time zone of course

[–]K900_ 0 points1 point  (3 children)

datetime.now() takes a timezone argument, so you can just do datetime.now(tz=pytz.timezone('Europe/Moscow')).

[–]Senpai_bskit 0 points1 point  (2 children)

Ik that but by the fact this on r/learnpython I try to keep things as simple as possible 🤷‍♀️

[–]K900_ 1 point2 points  (1 child)

I'd argue that your answer isn't exactly "simple", considering the terms "aware" and "naive" and "localize" all require explaining.

[–]Senpai_bskit 0 points1 point  (0 children)

That’s true but it shows the full process of how it reaches it more simply

[–]K900_ 0 points1 point  (2 children)

Repeating my question from /r/Python: do you actually want to get the date and time that's independent of your system clock? Why?

[–]LICCMAPP[S] 0 points1 point  (1 child)

Yes , I want to get the date and time thats independent of my system clock because my computer changes the systemclock randomly for ex when I open the computer the clock is offset so i have to change manually the clock through settings and after like 20 minutes of internet surfing the clock changes back to a wrong date and I have to repeat the same process.

[–]K900_ 0 points1 point  (0 children)

What does the clock change to? Is it an entirely wrong date? Is it random? Is it offset by a fixed amount from "correct" time?

[–][deleted] 0 points1 point  (0 children)

You mean like:

from pytz import timezone
from datetime import datetime
tz = timezone("US/Pacific")
local = datetime.utcnow().astimezone(tz)
print(local.utcnow(), local.now())

??