See the following example:
import datetime
now = datetime.datetime.now()
now.strftime('%Y-%m-%dT%H:%M:%S') + ('-%02d' % (now.microsecond / 10000))
This could result in the following: '2017-09-20T11:52:32-98'
Answer from Henk Dekker on Stack Overflow Top answer 1 of 2
62
See the following example:
import datetime
now = datetime.datetime.now()
now.strftime('%Y-%m-%dT%H:%M:%S') + ('-%02d' % (now.microsecond / 10000))
This could result in the following: '2017-09-20T11:52:32-98'
2 of 2
35
You can use datetime with strftime. Exemple:
import datetime
date = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")
print(date)
Will print:
2017-09-20T12:59:43.888955
Python documentation
docs.python.org โบ 3 โบ library โบ datetime.html
datetime โ Basic date and time types
Because naive datetime objects are treated by many datetime methods as local times, it is preferred to use aware datetimes to represent times in UTC. As such, the recommended way to create an object representing a specific timestamp in UTC is by calling datetime.fromtimestamp(timestamp, tz=timezone.utc).
Videos
00:55
How to get complete date and time timestamp format in Python - YouTube
08:44
Python: Dates, Times & Timestamps Part-1 | datetime, time libraries ...
Formatting a Local Timestamp in Python
11:29
HOW TO TUTORIAL: PYTHON DATE TIME | TIMESTAMP | STRING DATE | PARSE ...
01:58
Convert Datetime Format to Timestamp in Python - YouTube
12:15
How to Format Date and Time in Python | Python Tutorial for ...
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 ... Note: Note: It returns timestamp in float type to get timestamp without decimal value convert it to an integer using the int(ts) constructor. The time moduleโs time() method returns the current time in the timestamp format, which is nothing but the time elapsed from the epoch time, January 1, 1970.
Programiz
programiz.com โบ python-programming โบ datetime โบ strftime
Python strftime() - datetime to string
from datetime import datetime timestamp = 1528797322 date_time = datetime.fromtimestamp(timestamp) d = date_time.strftime("%c") print("Output 1:", d) d = date_time.strftime("%x") print("Output 2:", d) d = date_time.strftime("%X") print("Output 3:", d) ... Format codes %c, %x and %X are used ...
W3Schools
w3schools.com โบ python โบ python_datetime.asp
Python Dates
The method is called strftime(), and takes one parameter, format, to specify the format of the returned string: ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ยท If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com ยท HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
Tutorialspoint
tutorialspoint.com โบ python โบ python_date_time.htm
Python - Date and Time
fromtimestamp(timestamp, timezone.utc) โ On the POSIX compliant platforms, it is equivalent todatetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(seconds=timestamp) fromordinal(ordinal) โ Return the datetime corresponding to the proleptic Gregorian ordinal, where January 1 of year 1 has ordinal 1. fromisoformat(date_string) โ Return a datetime corresponding to a date_string in any valid ISO 8601 format.
GeeksforGeeks
geeksforgeeks.org โบ python โบ python-strftime-function
Python strftime() function - GeeksforGeeks
July 12, 2025 - Python provides the strftime() function lets us convert a datetime object into a formatted string using special format codes. These format codes represent different parts of the date and time-like year, month, weekday, hour, etc. Itโs especially useful when we need to display dates in a specific style or generate timestamps in logs and reports.
Pandas
pandas.pydata.org โบ docs โบ reference โบ api โบ pandas.to_datetime.html
pandas.to_datetime โ pandas 3.0.2 documentation
scalars can be int, float, str, datetime object (from stdlib datetime module or numpy). They are converted to Timestamp when possible, otherwise they are converted to datetime.datetime.
Pandas
pandas.pydata.org โบ docs โบ reference โบ api โบ pandas.Timestamp.html
pandas.Timestamp โ pandas 3.0.2 documentation
class pandas.Timestamp(ts_input=<object object>, year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None, tzinfo=None, *, nanosecond=None, tz=<object object>, unit=None, fold=None)[source]# Pandas replacement for python datetime.datetime object.
Slack
docs.slack.dev โบ methods โบ chat.postmessage
chat.postMessage method | Slack Developer Docs
This field represents the timestamp of the draft's last update at the time this API is called.
Twelve Data
twelvedata.com โบ docs
API Documentation - Twelve Data
The earliest_timestamp endpoint provides the earliest available date and time for a specified financial instrument at a given data interval.
LabEx
labex.io โบ tutorials โบ python-how-to-fix-python-time-formatting-489754
How to fix python time formatting | LabEx
This tutorial provides a comprehensive guide to mastering Python's time formatting techniques, helping programmers efficiently handle and manipulate time objects across various programming scenarios. Python provides robust tools for working with time and dates through various built-in modules. Understanding these basics is crucial for developers working on time-sensitive applications. Python offers several modules for time manipulation: import time import datetime ## Using time module current_timestamp = time.time() print("Current timestamp:", current_timestamp) ## Using datetime module current_datetime = datetime.datetime.now() print("Current datetime:", current_datetime)
MDN Web Docs
developer.mozilla.org โบ en-US โบ docs โบ Web โบ JavaScript โบ Reference โบ Global_Objects โบ Date โบ getTime
Date.prototype.getTime() - JavaScript | MDN
Date objects are fundamentally represented by a timestamp, and this method allows you to retrieve the timestamp. You can use this method to help assign a date and time to another Date object.
Python
docs.python.org โบ 3 โบ library โบ time.html
time โ Time access and conversions
The %f format directive only applies to strptime(), not to strftime(). However, see also datetime.datetime.strptime() and datetime.datetime.strftime() where the %f format directive applies to microseconds. When used with the strptime() function, the %p directive only affects the output hour field if the %I directive is used to parse the hour. The range really is 0 to 61; value 60 is valid in timestamps representing leap seconds and value 61 is supported for historical reasons.
Mimo
mimo.org โบ glossary โบ python โบ datetime
Python datetime Module: Working with Dates, Times, and Formatting
To work with dates and times in Python, you import the datetime object from the datetime module. The two most common operations are converting strings to datetime objects (strptime) and formatting datetime objects into strings (strftime).