“Python DateTime to Unix TimeStamp” Código de respuesta

Unix hasta la fecha Python

>>> from datetime import datetime
>>> ts = int("1284101485")

# if you encounter a "year is out of range" error the timestamp
# may be in milliseconds, try `ts /= 1000` in that case
>>> print(datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S'))
#'%Y' will be replaced by the year '%m' by the month '%d; by the day and so on 
#You move these how you want in the string, other characters will be ignored!
... '2010-09-10 06:51:25'
Paraducks

Cómo obtener la marca de tiempo de Unix en Python

import time
time.time() #returns the unix timestamp
Uninterested Unicorn

Python obtenga una fecha de la marca de tiempo de Unix

#get date from unix timestamp 
from datetime import date
timestamp = date.fromtimestamp(1326244364)
Kat

Convierta la marca de tiempo de DateTe a Unix en Python

from datetime import datetime

# current date and time
currentDateTime = datetime.now()
print("Current Date Time is ", currentDateTime)

# convert datetime to timestamp
timestamp = datetime.timestamp(currentDateTime)
print("Current Unix Timestamp is ", timestamp)
Gorgeous Gazelle

Python DateTime to Unix TimeStamp

from datetime import datetime, timedelta
import time
dtime = datetime.now() + timedelta(seconds=3)
unixtime = time.mktime(dtime.timetuple())
Silly Sicily Boy

Respuestas similares a “Python DateTime to Unix TimeStamp”

Preguntas similares a “Python DateTime to Unix TimeStamp”

Más respuestas relacionadas con “Python DateTime to Unix TimeStamp” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código