Timestamp (Python)
Versie door Jeroen Strompf (overleg | bijdragen) op 4 feb 2019 om 22:47
Interactief
strompf@dell2016 ~ $ python3 Python 3.5.2 (default, Nov 12 2018, 13:43:14) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> print time.time() File "<stdin>", line 1 print time.time() ^ SyntaxError: invalid syntax >>> print(time.time()) 1549312758.5469408 >>> import datetime >>> print(datetime.datetime.fromtimestamp(time.time()).strftime('%Y.%m.%d-%H.%M')) 2019.02.04-21.40 >>>
Programma
#! /usr/bin/python3 # # Timestamp ############################################################################# # import time import datetime time_stamp=datetime.datetime.fromtimestamp(time.time()).strftime('%Y.%m.%d-%H.%M') print(time_stamp)
Bronnen
https://stackoverflow.com/questions/13890935/does-pythons-time-time-return-the-local-or-utc-timestamp - Zie het interactieve voorbeeld. Werkt ook in Python3 (wel haakjes toevoegen bij print-opdracht)