Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python from timestamp to string

from datetime import datetime

timestamp = 1545730073
dt_object = datetime.fromtimestamp(timestamp)

print("dt_object =", dt_object)
print("type(dt_object) =", type(dt_object))

# Output

dt_object = "2018-12-25 09:27:53"
type(dt_object) = <class 'datetime.datetime'>
Comment

How to convert string date to timestamp in Python

import time
import datetime

# date in string format
dt="23/04/2022"

# convert into the time tuple
time_tuple=datetime.datetime.strptime(dt, "%d/%m/%Y").timetuple()
print("Time tuple format ",time_tuple)

# using mktime() convert to timestamp
print("The timestamp is ",time.mktime(time_tuple))
Comment

Python Creating string from a timestamp

from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)
Comment

create a timestamp python

import datetime
from datetime import datetime
timestamp = pd.Timestamp('2020-5-23')
Comment

PREVIOUS NEXT
Code Example
Python :: how to close windows in selenium python without quitting the browser 
Python :: round down a number python 
Python :: finding the Unique values in data 
Python :: list comprehenstsion using lambda funcion 
Python :: python read pdf 
Python :: playsound error 
Python :: how to print two lists side by side in python 
Python :: print index of tuple python 
Python :: roots of quadratic equation in python 
Python :: python append to first index 
Python :: how to convert days into seconds in python using time.time() 
Python :: replace character in string python 
Python :: create an environment in conda 
Python :: pytesseract.image_to_string save text file 
Python :: python print boolean 
Python :: how to get current date and time in python 
Python :: how to get the current year in python 
Python :: delete rows with value in column pandas 
Python :: list sort by key python 
Python :: django updated_at field 
Python :: code to calculate dice score 
Python :: Reverse an string Using Recursion in Python 
Python :: change size of plot python 
Python :: python check if all caps 
Python :: numpy count occurrences in array 
Python :: change python3 as default for mac 
Python :: for loop with index python3 
Python :: python write list to excel file 
Python :: create a dictionary in python 
Python :: df.iterrows() 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =