It appears to me that the simplest way to do this is

import datetime

epoch = datetime.datetime.utcfromtimestamp(0)

def unix_time_millis(dt):
    return (dt - epoch).total_seconds() * 1000.0
Answer from Sophie Alpert on Stack Overflow
Discussions

python - Converting Epoch time into the datetime - Stack Overflow
I am getting a response from the rest is an Epoch time format like start_time = 1234566 end_time = 1234578 I want to convert that epoch seconds in MySQL format time so that I could store the diffe... More on stackoverflow.com
๐ŸŒ stackoverflow.com
epoch to timestamp without time zone
Other people have answered how to fix your code, but more specifically, what you are missing is that the Unix epoch is defined in terms of UTC. Having it convert to a Datetime with UTC time zone is correct behavior. If you want it to be a time without any time zone (a "naive" time, in `chrono` parlance) then you have to explicitly drop the time zone. More on reddit.com
๐ŸŒ r/rust
7
0
November 4, 2022
How to convert a number of milliseconds since Year 0 into a pandas Timestamp (or some other object with year, month, day, hour, minute, second)?
my_dataframe.timestamp_column = pandas.to_datetime(my_dataframe.timestamp_column) That should automatically detect the input format (unix timestamp; the number of milli/seconds since 1st Jan 1970) and convert that column to a pandas.DateTime type. If the dates are still off then you can pass the exact unit to the method โ€‹ my_dataframe.timestamp_column = pandas.to_datetime(my_dataframe.timestamp_column, unit="ms") If you are working with a non-unix epoch (practically this just means the start of a range of time) you can pass the start date with the origin argument (starting at the new millenium for example): โ€‹my_dataframe.timestamp_column = pandas.to_datetime(my_dataframe.timestamp_column, unit="ms", origin=pd.Timestamp("2000-01-01")) More on reddit.com
๐ŸŒ r/learnpython
10
11
October 25, 2022
convert readable string to epoch time
If they are all in the same format, find the format string for your timestamps here: http://strftime.net/ Then you can use strptime to convert it to a struct tm - note, strptime is a POSIX function and not a C standard function, but it should be available on most systems. Then you can use mktime to convert it to a time_t (epoch). More on reddit.com
๐ŸŒ r/C_Programming
4
16
November 29, 2021
๐ŸŒ
GitHub
gist.github.com โ€บ evnm โ€บ d17336bf42e887c6e756
Script to convert milliseconds since epoch to a human-readable timestamp ยท GitHub
Script to convert milliseconds since epoch to a human-readable timestamp ยท Raw ยท gistfile1.py ยท This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ convert-python-datetime-to-epoch
Convert Python datetime to epoch - GeeksforGeeks
July 23, 2025 - The calendar module can also be used to convert a datetime object to epoch time using the timegm() function which directly works with UTC time. This function takes a timetuple() of the datetime object and converts it into the number of seconds ...
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-epoch-to-datetime
Epoch Time To Datetime Conversion In Python
August 12, 2025 - This is common with JavaScript APIs or certain databases. from datetime import datetime import pandas as pd def convert_millisecond_epoch(ms_epoch): """Convert millisecond epoch to datetime""" return datetime.fromtimestamp(ms_epoch / 1000) # Example: Processing mobile app analytics data app_events ...
๐ŸŒ
Hevodata
docs.hevodata.com โ€บ pipelines โ€บ transformations โ€บ python-transfm โ€บ timeutils โ€บ convert-epoch-to-datetime
Convert Epoch Time to a Datetime - Hevo Data
The following script takes an epoch value as an argument and returns a datetime object. from io.hevo.api import Event from io.hevo.api import TimeUtils def transform(event): # Get properties from the Event # <epoch> = <milliseconds_value> <date_object> = TimeUtils.fromEpochToDatetime(<epoch>) return <newEvent>
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-convert-python-datetime-string-into-integer-milliseconds
How to convert Python DateTime string into integer milliseconds?
August 28, 2025 - In the following program, we create a datetime object for January 1, 2018, using the datetime() method, then convert it into seconds since the epoch using the timestamp() method, and finally convert it into milliseconds (multiply by 1000) using the round() function.
Find elsewhere
๐ŸŒ
Javatpoint
javatpoint.com โ€บ python-epoch-to-datetime
Python epoch to Datetime - Javatpoint
October 6, 2021 - Python epoch to Datetime - Python epoch to Datetime with python, tutorial, tkinter, button, overview, entry, checkbutton, canvas, frame, environment set-up, first python program, operators, etc.
๐ŸŒ
Community
community.safe.com โ€บ transformers-9 โ€บ convert-epoch-datetime-from-milliseconds-timezone-to-other-format-3891
Convert epoch datetime from Milliseconds + TimeZone to Other format | Community
February 12, 2018 - Doesn't look like it, the FME Data/Time transformers don't support epochs in milliseconds, only seconds. ... from datetime import datetime, timedelta import time # oldtime = "1352984400000+1100" oldtime = feature.getAttribute('Oldtime') #Split into a list timebits = oldtime.split("+") #convert into seconds >> No loss of accuracy as its decimals epoch = int(timebits[0])/1000 #convert to python datetime format from epoch timestamp dt = 2012-11-15 13:00:00 dt = datetime.utcfromtimestamp(epoch) #add hours to datetime using timedelta NewTime = dt+ timedelta(hours=int(timebits[1])) #create new Attribute Newtime in the format %Y%m%d%H%M%S Newtime = 2012-12-31 09:00:00 feature.setAttribute('Newtime',NewTime.strftime("%Y%m%d%H%M%S"))
๐ŸŒ
PYnative
pynative.com โ€บ home โ€บ python โ€บ python datetime โ€บ python datetime to seconds
Python Datetime to Seconds โ€“ PYnative
May 17, 2022 - convert datetime to number of seconds since epoch in Python. Also convert seconds to datetime.
๐ŸŒ
Kontext
kontext.tech โ€บ home โ€บ blogs โ€บ code snippets & tips โ€บ convert timestamp to milliseconds since epoch in python
Convert Timestamp to Milliseconds since Epoch in Python - Kontext Labs
August 22, 2022 - This code snippets provides different approaches to convert a Python timestamp object to an integer that denotes the total milliseconds since Epoch (midnight 1st Jan 1970 UTC, UNIX time).
๐ŸŒ
Sou-Nan-De-Gesu
soudegesu.com โ€บ en โ€บ python โ€บ python-datetime
Convert a string representing the date or epoch time to datetime and change timezone in Python - Sou-Nan-De-Gesu
April 22, 2018 - 1import datetime 2 3mills = 1524349374.099776 4dt2 = datetime.datetime.fromtimestamp(mills) 5 6print(dt2) 7>> 2018-04-22 07:22:54.099776 ยท In milliseconds expressed as an integer (epoch millisecond notation), divide a value after checking how many digits represent milliseconds.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Convert Unix Time (Epoch Time) to and from datetime in Python | note.nkmk.me
April 29, 2025 - datetime.datetime.fromtimestamp() โ€” Python 3.13.3 documentation ยท By default, it returns the local date and time according to the system's timezone settings. For example, if your machine is set to Japan Standard Time (JST), the conversion will account for the +9 hour offset. ... import datetime dt = datetime.datetime.fromtimestamp(0) print(dt) # 1970-01-01 09:00:00 print(type(dt)) # <class 'datetime.datetime'> print(dt.tzinfo) # None
๐ŸŒ
PythonForBeginners.com
pythonforbeginners.com โ€บ home โ€บ convert epoch to datetime in python
Convert Epoch to Datetime in Python - PythonForBeginners.com
January 25, 2023 - To convert epoch to datetime in python, we can use the fromtimestamp() method defined in the datetime module. The fromtimestamp() method takes the epoch as its input argument and returns the datetime object.
๐ŸŒ
Oreate AI
oreateai.com โ€บ blog โ€บ unlocking-time-your-python-guide-to-epoch-to-datetime-conversions โ€บ 58f7e6815f95c46cbb0fa37b83f627fc
Unlocking Time: Your Python Guide to Epoch to Datetime Conversions - Oreate AI Blog
February 17, 2026 - The trick is to divide by 1000 to get the seconds before converting. import datetime epoch_with_ms = 1236472051807 # Convert milliseconds to seconds epoch_seconds = epoch_with_ms / 1000.0 dt_object = datetime.datetime.fromtimestamp(epoch_seconds) ...
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ time.html
time โ€” Time access and conversions
For related functionality, see also the datetime and calendar modules. Although this module is always available, not all functions are available on all platforms. Most of the functions defined in this module call platform C library functions with the same name. It may sometimes be helpful to consult the platform documentation, because the semantics of these functions varies among platforms. An explanation of some terminology and conventions is in order. The epoch is the point where the time starts, the return value of time.gmtime(0).
๐ŸŒ
pythontutorials
pythontutorials.net โ€บ blog โ€บ how-do-i-create-a-datetime-in-python-from-milliseconds
How to Create a Python Datetime from Milliseconds Since Epoch: Step-by-Step Guide โ€” pythontutorials.net
The key difference is scale: 1 second = 1000 milliseconds. Precision: Millisecond timestamps include fractional seconds (e.g., 1620000001234 = 1,620,000,001 seconds + 234 milliseconds).
๐ŸŒ
Tutorial Reference
tutorialreference.com โ€บ python โ€บ examples โ€บ faq โ€บ python-pandas-how-to-convert-epoch-to-datetime-in-dataframe
Python Pandas: How to Convert Epoch Time to Datetime (Seconds/Milliseconds) | Tutorial Reference
Epoch time, also known as Unix time or POSIX time, represents a point in time as the number of seconds (or milliseconds, microseconds, etc.) that have elapsed since 0000 Coordinated Universal Time (UTC) on Thursday, 1 January 1970. When working with datasets that store timestamps in Epoch format, you'll often need to convert these numerical timestamps into human-readable datetime objects in Pandas for easier analysis and manipulation.