Python | time.time() method Last Updated : 28 Aug, 2019 Comments Improve Suggest changes Like Article Like Report Time module in Python provides various time-related functions. This module comes under Python’s standard utility modules. time.time() method of Time module is used to get the time in seconds since epoch. The handling of leap seconds is platform dependent. Note: The epoch is the point where the time starts, and is platform dependent. On Windows and most Unix systems, the epoch is January 1, 1970, 00:00:00 (UTC) and leap seconds are not counted towards the time in seconds since the epoch. To check what the epoch is on a given platform we can use time.gmtime(0). Syntax: time.time() Parameter: No parameter is required Return type: This method returns a float value which represents the time in seconds since the epoch. Code #1: Use of time.time() method Python3 # Python program to explain time.time() method # importing time module import time # Get the epoch obj = time.gmtime(0) epoch = time.asctime(obj) print("epoch is:", epoch) # Get the time in seconds # since the epoch time_sec = time.time() # Print the time print("Time in seconds since the epoch:", time_sec) Output: epoch is: Thu Jan 1 00:00:00 1970 Time in seconds since the epoch: 1566454995.8361387 Code #2: Calculate seconds between two date Python3 # Python program to explain time.time() method # importing time module import time # Date 1 date1 = "1 Jan 2000 00:00:00" # Date 2 # Current date date2 = "22 Aug 2019 00:00:00" # Parse the date strings # and convert it in # time.struct_time object using # time.strptime() method obj1 = time.strptime(date1, "% d % b % Y % H:% M:% S") obj2 = time.strptime(date2, "% d % b % Y % H:% M:% S") # Get the time in seconds # since the epoch # for both time.struct_time objects time1 = time.mktime(obj1) time2 = time.mktime(obj2) print("Date 1:", time.asctime(obj1)) print("Date 2:", time.asctime(obj2)) # Seconds between Date 1 and date 2 seconds = time2 - time1 print("Seconds between date 1 and date 2 is % f seconds" % seconds) Output: Date 1: Sat Jan 1 00:00:00 2000 Date 2: Thu Aug 22 00:00:00 2019 Seconds between date 1 and date 2 is 619747200.000000 seconds Reference: https://docs.python.org/3/library/time.html#time.time Comment More infoAdvertise with us I ihritik Follow Improve Article Tags : Python python-utility Practice Tags : python Explore Python FundamentalsPython Introduction 3 min read Input and Output in Python 4 min read Python Variables 6 min read Python Operators 5 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 7 min read Python Functions 8 min read Recursion in Python 6 min read Python Lambda Functions 6 min read Python Data StructuresPython String 6 min read Python Lists 6 min read Python Tuples 6 min read Dictionaries in Python 7 min read Python Sets 10 min read Python Arrays 9 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 6 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 12 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 11 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 6 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library- Tutorial 4 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 7 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 10 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 3 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like