简体   繁体   中英

OS Time in Python 3.8.5

I've got the following dictionary in my code:

{
"morning": now.hour > 0,
"afternoon": now.hour > 12,
"evening": now.hour > 18,
"bit_late": now.hour > 21,
}

It's part of a Django project (v3.1), and whenever I run the server it throws up no errors, but it is using UTC time instead of my local system's time (+ 5 1/2 UTC). Hence, when I viewed the page at 3 PM, it wished me "Good morning" (which it's programmed to do). I've included the datetime library, but I don't know how to use it or any other library to try and get the program to run using system time.

Am I missing any particular library? What method should I use to get the system time, and where do I put it?

    now = datetime.datetime.now()

This is the code I used for now , just for reference!

Thanks in advance!

Yep, I've got my answer. I simply used JavaScript to display the message instead of trying something with Django. Thanks to everyone!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM