use time, and int to remove the milliseconds

from time import time 

int(time())

# 1561043225
Answer from Alex on Stack Overflow
🌐
PYnative
pynative.com › home › python › python datetime › python datetime to seconds
Python Datetime to Seconds – PYnative
May 17, 2022 - If your Python version is greater than 3.3 then another way is to use the timestamp() method of a datetime class to convert datetime to seconds. This method returns a float value representing even fractions of a second. from datetime import datetime # input datetime dt = datetime(2018, 10, ...
🌐
Flexiple
flexiple.com › python › python-timestamp
Python Timestamp - Get Current timestamp in Python - Flexiple
One approach to getting a timestamp in milliseconds involves utilizing the time module, specifically the time() function, which returns the current time in seconds since the epoch.
🌐
PYnative
pynative.com › home › python › python datetime › python convert seconds to hh:mm:ss (hours, minutes, and seconds)
Python Convert Seconds To hh:mm:ss (Hours, Minutes, and Seconds)
February 17, 2022 - def get_seconds(time_str): print('Time ... in Seconds: 315 Time in hh:mm:ss: 0:00:32 Time in Seconds: 32 · Get the current time in seconds using the timestamp() function...
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › convert-a-datetime-object-to-seconds
Convert A Datetime Object To Seconds - GeeksforGeeks
June 12, 2025 - Python · from datetime import ... 1748858115.766096 · Explanation: today() gets the current local datetime. timestamp() converts it into seconds from epoch....
🌐
GeeksforGeeks
geeksforgeeks.org › get-seconds-from-timestamp-in-python-pandas
Get Seconds from timestamp in Python-Pandas - GeeksforGeeks
April 5, 2022 - Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Timestamp.second attribute return an integer value which represents the value o · 2 min read Get Minutes from timestamp in Pandas-Python
🌐
Python documentation
docs.python.org › 3 › library › datetime.html
datetime — Basic date and time types
A timedelta object represents a duration, the difference between two datetime or date instances. class datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)¶
🌐
Timestamp Converter
timestamp.online › article › how-to-get-current-timestamp-in-python
How To Get Current Timestamp In Python - Code Example
Module datetime provides classes for manipulating date and time in more object oriented way. One of them is datetime.datetime.now which return number of seconds since the epoch. import datetime; ts = datetime.datetime.now().timestamp() print(ts) # 1767881785.1304 · Another way how to get current timestamp is to combine multiple functions from multiple modules. Python provides also calendar module.
🌐
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.
Find elsewhere
🌐
GitHub
github.com › pydantic › pydantic › issues › 7940
Please reconsider 'guessing' whether a timestamp is in milliseconds or seconds · Issue #7940 · pydantic/pydantic
October 27, 2023 - from datetime import datetime from pydantic import BaseModel class Foo(BaseModel): a: datetime # some timestamps in ms recent = datetime(2023, 10, 4, 12, 22).timestamp() * 1000 apollo17_launch = datetime(1972, 12, 7, 5, 33).timestamp() * 1000 apollo13_launch = datetime(1970, 4, 11, 19, 13).timestamp() * 1000 print(Foo(a=recent)) # 2023-10-04 (correct) print(Foo(a=apollo17_launch)) # 1972-12-07 (correct) print(Foo(a=apollo13_launch)) # 2245-11-14 (INCORRECT) pydantic version: 2.4.2 pydantic-core version: 2.10.1 pydantic-core build: profile=release pgo=false install path: /Users/arie/.pyenv/versions/3.12.0/envs/sandbox312/lib/python3.12/site-packages/pydantic python version: 3.12.0 (main, Oct 3 2023, 08:33:34) [Clang 15.0.0 (clang-1500.0.40.1)] platform: macOS-14.0-arm64-arm-64bit related packages: typing_extensions-4.8.0
Author   ariebovenberg
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-datetime-to-integer-timestamp
Datetime to integer timestamp in Python - GeeksforGeeks
July 23, 2025 - A timestamp represents the number of seconds that have passed since January 1, 1970, 00:00:00 UTC (also known as the epoch). We can convert a datetime object to a timestamp using the built-in timestamp() method, and then round or typecast it ...
🌐
Learn By Example
learnbyexample.org › working-with-timestamps-in-python
Working with Timestamps in Python - Learn By Example
April 23, 2024 - However, there are situations like ... in milliseconds in Python, you can take the timestamp in seconds (obtained from either datetime.now().timestamp() or time.time()) and multiply it by 1000....
🌐
Epoch Converter
epochconverter.com
Epoch Converter - Unix Timestamp Converter
Some systems store epoch values as signed 32-bit integers, which can break on January 19, 2038, in the Year 2038 Problem. This page converts timestamps in seconds (10 digits), milliseconds (13 digits), and microseconds (16 digits) into readable dates.
🌐
PYnative
pynative.com › home › python › python datetime › timestamp in python
Timestamp In Python
December 5, 2021 - The time module‘s time() method ... the epoch time, January 1, 1970. ... Definition: This function returns the time in seconds since the epoch as a floating-point number....
🌐
GeeksforGeeks
geeksforgeeks.org › get-current-timestamp-using-python
Get Current Timestamp Using Python - GeeksforGeeks
May 5, 2025 - A timestamp is a sequence of characters ... to fractions of a second. Timestamps are essential in logging events, tracking files, and handling date-time data in various applications. There are 3 different ways to get the current timestamp in Python, let's explore these ...
🌐
Studytonight
studytonight.com › python-howtos › how-to-convert-a-datetime-object-to-seconds
How to convert a datetime object to seconds? - Studytonight
February 16, 2021 - The value returned is a timedelta object from which we can use the function total_seconds() to get the value in seconds. import datetime time = "01:01:09" date_time = datetime.datetime.strptime(time, "%H:%M:%S") a_timedelta = date_time - ...
🌐
Python
docs.python.org › 3 › library › time.html
time — Time access and conversions
The range really is 0 to 61; value 60 is valid in timestamps representing leap seconds and value 61 is supported for historical reasons.
🌐
Programiz
programiz.com › python-programming › datetime › timestamp-datetime
Python timestamp to datetime and vice-versa (With Examples)
December 25, 2018 - from datetime import datetime # timestamp is number of seconds since 1970-01-01 timestamp = 1545730073 # convert the timestamp to a datetime object in the local timezone dt_object = datetime.fromtimestamp(timestamp) # print the datetime object and its type print("dt_object =", dt_object) print("type(dt_object) =", type(dt_object))
🌐
Flexiple
flexiple.com › python › python-unix-timestamp
Converting DateTime to UNIX Timestamp in Python - Flexiple
Once the DateTime object is in UTC, the timestamp() method converts it into a UNIX timestamp, representing the number of seconds since the UNIX epoch (January 1, 1970, at 00:00 UTC).