First the quick and dirty way, and second the precise way (recognizing daylight's savings or not).

import time
time.ctime() # 'Mon Oct 18 13:35:29 2010'
time.strftime('%l:%M%p %Z on %b %d, %Y') # ' 1:36PM EDT on Oct 18, 2010'
time.strftime('%l:%M%p %z on %b %d, %Y') # ' 1:36PM EST on Oct 18, 2010'
Answer from dr jimbob on Stack Overflow
๐ŸŒ
Real Python
realpython.com โ€บ python-get-current-time
How to Get and Use the Current Time in Python โ€“ Real Python
September 25, 2023 - Getting the current time in Python is a nice starting point for many time-related operations. One very important use case is creating timestamps. In this tutorial, youโ€™ll learn how to get, display, and format the current time with the datetime module.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ get-current-timestamp-using-python
Get Current Timestamp Using Python - GeeksforGeeks
May 5, 2025 - The datetime module provides the now() function to get the current date and time, and the timestamp() method converts it to a timestamp.
๐ŸŒ
PYnative
pynative.com โ€บ home โ€บ python โ€บ python datetime โ€บ timestamp in python
Python Timestamp With Examples โ€“ PYnative
December 5, 2021 - from datetime import datetime # Getting the current date and time dt = datetime.now() # getting the timestamp ts = datetime.timestamp(dt) print("Date and time is:", dt) print("Timestamp is:", ts)Code language: Python (python) Run ...
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ datetime.html
datetime โ€” Basic date and time types
Return the current local date and time. If optional argument tz is None or not specified, this is like today(), but, if possible, supplies more precision than can be gotten from going through a time.time() timestamp (for example, this may be possible on platforms supplying the C gettimeofday() function).
๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ python-timestamp
Python Timestamp - Get Current timestamp in Python - Flexiple
Get Current TimestampDatetime to TimestampGet Timestamp Using time ModuleGet Timestamp Using calendar ModuleConvert Timestamp to Datetime (format)Convert Timestamp to StringGet Timestamp in MillisecondsGet The UTC TimestampTimestamp from Datetime with a Different TimezoneConvert an Integer Timestamp to Datetime ... A timestamp in Python represents the current time, typically in seconds or milliseconds since the epoch.
๐ŸŒ
Replit
replit.com โ€บ home โ€บ discover โ€บ how to get a timestamp in python
How to get a timestamp in Python | Replit
March 3, 2026 - Capturing the current moment with datetime.now(). Formatting it into a clean "YYYY-MM-DD HH:MM:SS" string using strftime(). This standardization is key for creating logs that are easy for both humans and machines to parse.
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ python-basic-exercise-3.php
Python: Print current time and date - w3resource
... # Import the 'datetime' module ... date and time : ") # Print the current date and time in a specific format print(now.strftime("%Y-%m-%d %H:%M:%S")) # Use the 'strftime' method to format the datetime object as a string with ...
Find elsewhere
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ get-current-time-python
How to Get Current Time in Python? (All Examples)
April 7, 2023 - If you want to print the current time in a specific format, you can use the strftime() function. The below code with print time in the format HH:MM:SS. import datetime current_time = datetime.datetime.now() formatted_time = current_time.str...
Top answer
1 of 10
924

The time.time() function returns the number of seconds since the epoch, as a float. Note that โ€œthe epochโ€ is defined as the start of January 1st, 1970 in UTC. So the epoch is defined in terms of UTC and establishes a global moment in time. No matter where on Earth you are, โ€œseconds past epochโ€ (time.time()) returns the same value at the same moment.

Here is some sample output I ran on my computer, converting it to a string as well.

>>> import time
>>> ts = time.time()
>>> ts
1355563265.81
>>> import datetime
>>> datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
'2012-12-15 01:21:05'
>>>

The ts variable is the time returned in seconds. I then converted it to a human-readable string using the datetime library.

2 of 10
348

This is for the text form of a timestamp that can be used in your text files. (The title of the question was different in the past, so the introduction to this answer was changed to clarify how it could be interpreted as the time. [updated 2016-01-14])

You can get the timestamp as a string using the .now() or .utcnow() of the datetime.datetime:

>>> import datetime
>>> print datetime.datetime.utcnow()
2012-12-15 10:14:51.898000

The now differs from utcnow as expected -- otherwise they work the same way:

>>> print datetime.datetime.now()
2012-12-15 11:15:09.205000

You can render the timestamp to the string explicitly:

>>> str(datetime.datetime.now())
'2012-12-15 11:15:24.984000'

Or you can be even more explicit to format the timestamp the way you like:

>>> datetime.datetime.now().strftime("%A, %d. %B %Y %I:%M%p")
'Saturday, 15. December 2012 11:19AM'

If you want the ISO format, use the .isoformat() method of the object:

>>> datetime.datetime.now().isoformat()
'2013-11-18T08:18:31.809000'

You can use these in variables for calculations and printing without conversions.

>>> ts = datetime.datetime.now()
>>> tf = datetime.datetime.now()
>>> te = tf - ts
>>> print ts
2015-04-21 12:02:19.209915
>>> print tf
2015-04-21 12:02:30.449895
>>> print te
0:00:11.239980
๐ŸŒ
JanBask Training
janbasktraining.com โ€บ community โ€บ python-python โ€บ how-do-i-get-the-current-time-in-python
How do I get the current time in Python? | JanBask Training Community
May 20, 2025 - Hereโ€™s a simple and effective way using the datetime module: from datetime import datetime now = datetime.now() print("Current Time:", now.strftime("%H:%M:%S")) This will give you the current time formatted in hours, minutes, and seconds.
๐ŸŒ
IPSERVERONE
ipserverone.info โ€บ knowledge-base โ€บ how-to-generate-the-current-timestamp-using-python
How to Generate the Current Timestamp Using Python - IPSERVERONE
January 15, 2025 - Basic knowledge of Python syntax and programming concepts. ... formatted_timestamp = current_timestamp.strftime("%Y-%m-%d %H:%M:%S") print("Formatted Timestamp:", formatted_timestamp)
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ datetime โ€บ current-datetime
How to get current date and time in Python? (With Examples)
Here, we have used datetime.now() to get the current date and time. Then, we used strftime() to create a string representing date and time in another format.
๐ŸŒ
Codedamn
codedamn.com โ€บ news โ€บ python
Working with Timestamps in Python
July 3, 2023 - from datetime import datetime current_timestamp = datetime.now() formatted_timestamp = current_timestamp.strftime('%Y-%m-%d %H:%M:%S') print(formatted_timestamp) In this example, '%Y-%m-%d %H:%M:%S' is the format string.
๐ŸŒ
Milddev
milddev.com โ€บ python-get-current-timestamp
Python Get Current Timestamp
July 27, 2025 - Learn to fetch and format the current timestamp in Python using time, datetime, zoneinfo, and third-party tools with code examples.
๐ŸŒ
TechBeamers
techbeamers.com โ€บ get-current-timestamp-in-python
Python Get Current Timestamp String - TechBeamers
November 30, 2025 - # Example 2: Get current timestamp in seconds and then convert it import time current_time = datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d %H:%M:%S") print(current_time) ...
๐ŸŒ
DEV Community
dev.to โ€บ hrishikesh1990 โ€บ how-to-get-timestamp-in-python-3flf
How to get Timestamp in Python? - DEV Community
April 20, 2022 - The example above returns the timestamp in the format HH:AM/PM MM:SS. Thus, the current timestamp can be converted to different formats as per our requirement. In this tutorial, we understood what timestamp is. We saw how to get a current timestamp in Python and convert it to different date and time formats.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-get-the-current-time-in-python-with-datetime
How to Get the Current Time in Python with Datetime
March 21, 2022 - To get the current time in particular, you can use the strftime() method and pass into it the string โ€%H:%M:%Sโ€ representing hours, minutes, and seconds. This would give you the current time in a 24Hour format:
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-get-current-system-timestamp-435417
How to get current system timestamp | LabEx
import time ## Current Unix timestamp current_timestamp = time.time() print(f"Unix Timestamp: {current_timestamp}") ## Formatted timestamp formatted_time = time.ctime(current_timestamp) print(f"Formatted Time: {formatted_time}")