Ejemplo 1: unix hasta la fecha de 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'
Ejemplo 2: Python de marca de tiempo
from datetime import datetime
# current date and time
now = datetime.now()
timestamp = datetime.timestamp(now)
print("timestamp =", timestamp)
Ejemplo 3: marca de tiempo hasta la fecha de Python
from datetime import datetime
timestamp = 1586507536367
dt_object = datetime.fromtimestamp(timestamp)
Ejemplo 4: convertir la marca de tiempo a la fecha usando Python
from datetime import datetime
timestamp = 1545730073
dt_object = datetime.fromtimestamp(timestamp)
print("dt_object =", dt_object)
print("type(dt_object) =", type(dt_object))
Ejemplo 5: convertir unix entero en python de marca de tiempo
import datetime
print(
datetime.datetime.fromtimestamp(
int("1284105682")
).strftime('%Y-%m-%d %H:%M:%S')
)
Ejemplo 6: pandas datetime a unix timestamp
dates = pd.to_datetime(['2019-01-15 13:30:00'])
(dates - pd.Timestamp("1970-01-01")) // pd.Timedelta('1s')
# Int64Index([1547559000], dtype="int64")
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)