Timestamp (Python)

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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)