How to get UNIX-time in Python?


UNIX-time (Eng. Unix time) or POSIX-time – system describe points in time, accepted as UNIX and other POSIX-compliant operating systems. Defined as the number of seconds that have passed since midnight (00:00:00 UTC) January 1, 1970 (Thursday); time from now called the “era of UNIX» (Eng. Unix Epoch).

UNIX is consistent with Time UTC – particularly at the announcement of leap seconds UTC appropriate accommodation seconds repeated that leap seconds are not counted.

Presentation time as the number of seconds is useful for comparison and storage of dates (date and time in this format is only 4 or 8 bytes). If you need to access the elements of the date (day, month, year) seconds can turn into any suitable format (and vice versa).

The programs to store UNIX-time uses symbolic integer type. Symbolic computation simplifies the difference in seconds between the two time points, which can be negative. 32-bit number with the sign may refer to the times from Friday 13 December 1901 20:45:52 until Tuesday January 19, 2038 3:14:07 inclusive.

In Python:

import calendar
import time
unix_time = calendar.timegm(time.gmtime())
print unix_time

Source: The experience and Wikipedia

Добавить комментарий

Этот сайт использует Akismet для борьбы со спамом. Узнайте как обрабатываются ваши данные комментариев.