Answers for "convert unix timestamp to datetime python"

3

unix to date 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'
Posted by: Guest on March-25-2021
9

timestamp to date python

from datetime import datetime

timestamp = 1586507536367
dt_object = datetime.fromtimestamp(timestamp)
Posted by: Guest on April-10-2020
1

convert integer unix to timestamp python

import datetime
print(
    datetime.datetime.fromtimestamp(
        int("1284105682")
    ).strftime('%Y-%m-%d %H:%M:%S')
)
Posted by: Guest on November-16-2020
0

python datetime to unix timestamp

from datetime import datetime, timedelta
import time
dtime = datetime.now() + timedelta(seconds=3)
unixtime = time.mktime(dtime.timetuple())
Posted by: Guest on October-31-2021
0

python convert ftp timestamp to datetime

ftp = FTP(host="127.0.0.1", user="u",passwd="p")
ftp.cwd("/data")
file_name = sorted(ftp.nlst(), key=lambda x: ftp.voidcmd(f"MDTM {x}"))[-1]
Posted by: Guest on May-27-2020
0

python convert ftp timestamp to datetime

from dateutil import parser

# ...

lines = []
ftp.dir("", lines.append)

latest_time = None
latest_name = None

for line in lines:
    tokens = line.split(maxsplit = 9)
    time_str = tokens[5] + " " + tokens[6] + " " + tokens[7]
    time = parser.parse(time_str)
    if (latest_time is None) or (time > latest_time):
        latest_name = tokens[8]
        latest_time = time

print(latest_name)
Posted by: Guest on May-27-2020

Code answers related to "convert unix timestamp to datetime python"

Python Answers by Framework

Browse Popular Code Answers by Language