“Python Date de l'horodatage” Réponses codées

horodatage à ce jour python

from datetime import datetime

timestamp = 1586507536367
dt_object = datetime.fromtimestamp(timestamp)
Beautiful Bear

Obtenez l'horodatage de String Python

import datetime
date = '18/05/2020 - 18:05:12'

# convert string to datetimeformat
date = datetime.datetime.strptime(date, "%d %m %Y - %H:%M:%S")

# convert datetime to timestamp
date = datetime.datetime.timestamp(date)
arne314

Python Datetime à horodatage

import datetime
now = datetime.datetime.today()
timestamp = datetime.datetime.timestamp(now)
Angry Angelfish

horodatage en python

import time 
ts = time.time() 
// OR
import datetime; 
ct = datetime.datetime.now() 
ts = ct.timestamp() 
Tommy

Python Date de l'horodatage

>>> import time
>>> import datetime
>>> s = "01/12/2011"
>>> time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple())
1322697600.0
Vivacious Vendace

Python Date de l'horodatage

import datetime
import pytz
# naive datetime
d = datetime.datetime.strptime('01/12/2011', '%d/%m/%Y')
>>> datetime.datetime(2011, 12, 1, 0, 0)

# add proper timezone
pst = pytz.timezone('America/Los_Angeles')
d = pst.localize(d)
>>> datetime.datetime(2011, 12, 1, 0, 0,
tzinfo=<DstTzInfo 'America/Los_Angeles' PST-1 day, 16:00:00 STD>)

# convert to UTC timezone
utc = pytz.UTC
d = d.astimezone(utc)
>>> datetime.datetime(2011, 12, 1, 8, 0, tzinfo=<UTC>)

# epoch is the beginning of time in the UTC timestamp world
epoch = datetime.datetime(1970,1,1,0,0,0,tzinfo=pytz.UTC)
>>> datetime.datetime(1970, 1, 1, 0, 0, tzinfo=<UTC>)

# get the total second difference
ts = (d - epoch).total_seconds()
>>> 1322726400.0
Vivacious Vendace

Réponses similaires à “Python Date de l'horodatage”

Questions similaires à “Python Date de l'horodatage”

Plus de réponses similaires à “Python Date de l'horodatage” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code