Python Current Time How to Get

Getting Current Time in Python

Sample code showing how to get the current time in Python and display it as a timestamp.

Shou Arisaka
1 min read
Oct 9, 2025

How to Get Current Time in Python

Here’s sample code showing how to get the current time using Python and display it as a timestamp.

import time
import datetime

def number_ts():
    ts = time.time()
    beautiful_ts = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
    number_ts = datetime.datetime.fromtimestamp(ts).strftime('%Y%m%d%H%M%S')
    return number_ts

print(number_ts())

This code uses the number_ts() function to get the current timestamp as a number and displays it. For detailed explanations and other time formats, please refer to Python’s documentation.

Share this article

Shou Arisaka Oct 9, 2025

🔗 Copy Links