Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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'
Comment

Convert DateTime to Unix timestamp in 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)
Comment

datetime to unix timestamp python

# importing datetime module
import datetime
import time
 
# assigned regular string date
date_time = datetime.datetime(2021, 7, 26, 21, 20)
 
# print regular python date&time
print("date_time =>",date_time)
 
# displaying unix timestamp after conversion
print("unix_timestamp => ",
      (time.mktime(date_time.timetuple())))
Comment

python datetime to unix timestamp

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

PREVIOUS NEXT
Code Example
Python :: renaming headers pandasd 
Python :: django flash message 
Python :: start a simple http server python3 
Python :: simple imputer python 
Python :: get diroctary in python 
Python :: python matplotlib log scale 
Python :: sns figsize 
Python :: python check if internet is available 
Python :: python read xlsb pandas 
Python :: ind vs wi 
Python :: python reimport module 
Python :: show image in tkinter pillow 
Python :: python resize image 
Python :: correlation plot python seaborn 
Python :: get current date in python 
Python :: opencv draw a point 
Python :: python get absolute path of file 
Python :: ValueError: cannot mask with array containing NA / NaN values 
Python :: get mouse postition python 
Python :: add conda env to jupyter 
Python :: shuffle dataframe python 
Python :: sum number in a list python using recursion 
Python :: pandas append csv files a+ 
Python :: how to search for a specific file extension with python 
Python :: django user form 
Python :: pandas reset row indices 
Python :: python keylogger 
Python :: python replace backslash with forward slash 
Python :: purge command discord.py 
Python :: find all nan columns pandas 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =