Get Current time | Python
The datetime.now().time() is a class method that returns the current time.
>>> import datetime
>>> print(datetime.datetime.now().time())
12:15:45.245136
This method uses the time.localtime without the timezone info.
>>> import datetime
>>> print(datetime.datetime.now())
2021-08-25 12:16:02.613020
Get current time - python3

**datetime.utcnow() is a non-timezone aware object.
Python time interval measurement
The Python time() function returns the number of seconds passed since epoch.
>>> from time import time
>>> milliseconds = time()
>>> print(milliseconds)
1629874049.2520282
milliseconds - float number, good for time interval measurement. For the standard CPython implementation on most platforms this will return a UTC value.
Isoformat() of Time Class In Python
The method isoformat() returns the time as a string in the format as specified by the ISO 8601 standard. The return value can contain a string of minimum length 2, representing HH for hours and of maximum length 15, representing HH:MM:SS:ssssss.
>>> import datetime
>>> datetime.datetime.now().isoformat()
'2021-08-25T12:18:08.371450'
Get current time using Python pandas
>>> import pandas as pd
>>> print(pd.datetime.now())
2021-08-25 12:18:38.629239
Get current time using numpy
>>> import numpy as np
>>> str(np.datetime64('now'))
'2021-08-25T06:48:56'
Related Topics
- How to use Date and Time in Python
- Python Exception Handling
- How to Generate a Random Number in Python
- How to pause execution of program in Python
- How do I parse XML in Python?
- How to read and write a CSV files with Python
- Threads and Threading in Python
- Python Multithreaded Programming
- Python range() function
- How to Convert a Python String to int
- Python filter() Function
- Difference between range() and xrange() in Python
- How to print without newline in Python?
- How to remove spaces from a string in Python
- Slicing in Python
- Create a nested directory without exception | Python
- How to measure time taken between lines of code in python?
- How to concatenate two lists in Python
- How to Find the Mode in a List Using Python
- Difference Between Static and Class Methods in Python?