[image] James Parrott:
I’m impressed by the amount of effort you’ve put in to this. If there’s a straightforward solution then fantastic.
Thanks. I think one simple solution would be to support something like datetime.now(tz=timezone.local), where timezone.local is not an actual tzinfo instan… Answer from rohanpadhye on discuss.python.org
Python documentation
docs.python.org › 3 › library › datetime.html
datetime — Basic date and time types
As such, the recommended way to create an object representing the current time in UTC is by calling datetime.now(timezone.utc).
Code.mu
code.mu › en › python › manual › time › datetime › now
The now method of the datetime module - current time in Python
import datetime res = datetime.datetime.now() print(res.day) print(res.month) print(res.year) print(res.hour) print(res.minute) print(res.second)
Videos
12:41
Master Python's Datetime Module: Current Date, Time, and Custom ...
04:59
How do I get a value of datetime.today() in Python that is "timezone ...
06:18
Learn Python DATES & TIMES in 6 minutes! 📅 - YouTube
12:07
Python Datetime SIMPLY explained with examples - YouTube
06:46
Python Date, Time, and Datetime Classes | Working with Dates & ...
00:45
Current Datetime in Python #programming #code #coding #datetime ...
freeCodeCamp
freecodecamp.org › news › python-datetime-now-how-to-get-todays-date-and-time
Python Datetime.now() – How to Get Today's Date and Time
September 20, 2022 - You can use the datetime module in Python to retrieve data about date and time. In this article, you'll learn how to use the datetime object from the datetime module to get the current date and time properties. You'll also learn how to get the date and time of different locations around the world using the datetime.now() function and the pytz module.
Luasoftware
code.luasoftware.com › tutorials › python › python-get-today-without-time
Python Get Today Date Without Time
August 9, 2019 - import datetimetoday = datetime.datetime.today()today = today.replace(hour=0, minute=0, second=0, microsecond=0)
X
x.com › realpython › status › 2013642771077243358
How to Get and Use the Current Time in Python
Build Physical Projects With Python on the Raspberry Pi — https://realpython.com/python-raspberry-pi/… #python ... Sign up now to get your own personalized timeline!
W3Schools
w3schools.com › python › python_datetime.asp
Python Datetime
import datetime x = datetime.datetime.now() print(x.year) print(x.strftime("%A")) Try it Yourself »
Top answer 1 of 15
4
[image] James Parrott:
I’m impressed by the amount of effort you’ve put in to this. If there’s a straightforward solution then fantastic.
Thanks. I think one simple solution would be to support something like datetime.now(tz=timezone.local), where timezone.local is not an actual tzinfo instan…
2 of 15
1
I’m impressed by the amount of effort you’ve put in to this. If there’s a straightforward solution then fantastic. Otherwise, unfortunately, I think the best thing to take away from it is your superb example of an edge case:
if this code was to be executed on a mobile device that is physically m…
Educative
educative.io › answers › what-is-the-datetime-datetoday-function-in-python
What is the datetime date.today() function in Python?
In Python, there are multiple ways to extract the current date. In this shot, we will use the today() method from the date class of the datetime module. The datetime.now() method can extract the current date and time.
DigitalOcean
digitalocean.com › community › tutorials › python-current-date-time
Python Current Date Time | DigitalOcean
August 3, 2022 - We can use Python datetime module to get the current date and time of the local system. from datetime import datetime # Current date time in local system print(datetime.now())
Top answer 1 of 16
4050
Use datetime:
>>> import datetime
>>> now = datetime.datetime.now()
>>> now
datetime.datetime(2009, 1, 6, 15, 8, 24, 78915)
>>> str(now)
'2009-01-06 15:08:24.078915'
For just the clock time without the date:
>>> now.time()
datetime.time(15, 8, 24, 78915)
>>> str(now.time())
'15:08:24.078915'
To save typing, you can import the datetime object from the datetime module:
from datetime import datetime
Then remove the prefix datetime. from all of the above.
2 of 16
1240
Use time.strftime():
>>> from time import gmtime, strftime
>>> strftime("%Y-%m-%d %H:%M:%S", gmtime())
'2009-01-05 22:14:39'
PYnative
pynative.com › home › python › python datetime › how to get current date and time in python
Python Get Current Date and Time [8 Ways] – PYnative
December 5, 2021 - Python’s datetime module provides functions that handle many complex functionalities involving the date and time. Import the datetime class using a from datetime import datetime statement. ... The datetime.now() returns the current local date and time. By default, it represents datetime in ...
Codecademy
codecademy.com › docs › python › dates › datetime.now()
Python | Dates | datetime.now() | Codecademy
June 19, 2025 - The datetime.now() method is a class method from Python’s datetime module that returns a datetime object representing the current local date and time. This method captures the exact moment when it is called, including the year, month, day, ...
TutorialsPoint
tutorialspoint.com › article › what-is-the-difference-between-python-functions-datetime-now-and-datetime-today
What is the difference between Python functions datetime. ...
June 13, 2020 - Python TechnologiesDatabasesComputer ... All Categories ... The datetime.now() and datetime.today() functions both return the current local date and time, but they differ in their parameters and precision capabilities....
Mimo
mimo.org › glossary › python › datetime
Python datetime Module: Working with Dates, Times, and Formatting
Get Current Time with .now(): The datetime.now() method is the standard way to get the current local date and time. Use timedelta for Calculations: The timedelta object is essential for performing date arithmetic, such as adding or subtracting days, hours, or minutes from a datetime object.
SpeedySense
speedysense.com › home › python › how to get current date and time in python
How to get current date and time in Python - SpeedySense
November 9, 2020 - from datetime import datetime now = datetime.now() print (now.strftime("%Y-%m-%d %H:%M:%S")) print (now.strftime("%Y-%m-%d %I:%M:%S %p")) print (now.strftime("%a, %b %d, %Y")) print (now.strftime("%Y/%m/%d")) print (now.strftime("%I:%M:%S %p")) print (now.strftime("%H:%M:%S")) 2020-02-01 17:09:52 2020-02-01 05:09:52 PM Sat, Feb 01, 2020 2020/02/01 05:09:52 PM 17:09:52 · You can use the following list of directives to format the date and time with the strftime method. For more reference check it out datetime Objects in the datetime module from Python Standard Library Reference.
Programiz
programiz.com › python-programming › datetime
Python datetime (With Examples)
To learn more about strptime() and format codes, visit: Python strptime(). Suppose, we are working on a project and need to display date and time based on their timezone. Rather than trying to handle the timezone yourself, we suggest using a third-party pytZ module. from datetime import datetime import pytz local = datetime.now() print("Local:", local.strftime("%m/%d/%Y, %H:%M:%S")) tz_NY = pytz.timezone('America/New_York') datetime_NY = datetime.now(tz_NY) print("NY:", datetime_NY.strftime("%m/%d/%Y, %H:%M:%S")) tz_London = pytz.timezone('Europe/London') datetime_London = datetime.now(tz_London) print("London:", datetime_London.strftime("%m/%d/%Y, %H:%M:%S"))