Home > Article > Backend Development > How to get timestamp in python? How to get current timestamp?
Today in this article we will talk about the date and time in python. Maybe for friends who have just started learning the programming language python, how to get the python current timestamp in python,Let you know how to get the current timestamp using python.
Python programs can handle dates and times in many ways, and converting date formats is a common function.
Python provides a time and calendar modules that can be used to format dates and times.
The time interval is a floating point fraction in seconds.
Each timestamp is expressed as how much time has passed since midnight (epoch) on January 1, 1970.
There are many functions under Python’s time module that can convert common date formats. For example, the function time.time() is used to obtain the python timestamp, as in the following example:
#!/usr/bin/python # -*- coding: UTF-8 -*- import time; # 引入time模块 ticks = time.time() print "当前时间戳为:", ticks
The output result of the above example is as shown in the figure below:
当前时间戳为: 1534234614.98
(The timestamp unit is most suitable for date calculations. However, dates before 1970 cannot be expressed in this way. Dates that are too far away will not work either. UNIX and Windows only support 2038.)
In this article, we learned how to get the current timestamp in python, and I used an example to demonstrate how to get the latest timestamp. I also hope that this article can A little help for you who are learning python.
For more related knowledge, please visit the Python tutorial column on the php Chinese website.
The above is the detailed content of How to get timestamp in python? How to get current timestamp?. For more information, please follow other related articles on the PHP Chinese website!