Python Glossary Русский

all Python 3sqlite3function

sqlite3.TimestampFromTicks()

DB-API: date and time

A DB-API standard function: turns seconds since the epoch into a naive datetime.datetime in the local time zone.

Syntax

sqlite3.TimestampFromTicks(ticks)

Unlike datetime.datetime.fromtimestamp, microseconds are dropped: TimestampFromTicks(1.9) gives 00:00:01 while fromtimestamp gives 00:00:01.900000. The result is naive (tzinfo=None) and depends on the machine's zone, so for storage it is safer to keep the raw seconds or a UTC time.

Examples

import datetime
import sqlite3
print(sqlite3.TimestampFromTicks(1.9))  # → ? 1970-01-01 00:00:01 в UTC
print(datetime.datetime.fromtimestamp(1.9).microsecond)  # → 900000
print(sqlite3.TimestampFromTicks(1.9).microsecond)  # → 0
print(sqlite3.TimestampFromTicks(0).tzinfo)  # → None

See also

Open in the full glossarydocs.python.orgReport an inaccuracy