Jump to content

Timp rămas până la zilele B-Zone

V-am pregătit o mulțime de evenimente. Click aici

La mulți ani B-ZONE!

V-am pregătit o mulțime de evenimente. Click aici

[Python]Marcajul temporal Python la datetime si invers


iza
 Share

Recommended Posts

Exemplul 1: Marcajul temporal Python la datetime:

from datetime import datetime

timestamp = 1545730073
dt_object = datetime.fromtimestamp(timestamp)

print("dt_object =", dt_object)
print("type(dt_object) =", type(dt_object))

Cand executati programul, rezultatul va fi:

dt_object = 2018-12-25 09:27:53
type(dt_object) = <class 'datetime.datetime'>

Aici, am importat clasa datetime din modulul datetime. Apoi, am folosit datetime.fromtimestamp() classmethod care returneaza data si ora locala (obiectul datetime). Acest obiect este stocat in dt_object .

 

Exemplul 2: Python datetime to timestamp:

from datetime import datetime

# current date and time
now = datetime.now()

timestamp = datetime.timestamp(now)
print("timestamp =", timestamp)


 

Link to comment
Share on other sites

  • Tupi locked this topic
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.