Python Datetime ExamplesΒΆ

import datetime

# Create a datetime object for May 14, 2024
date_example = datetime.datetime(2024, 5, 14)

# Format the datetime object into a more readable string
formatted_date = date_example.strftime('%A, %B %d, %Y')

print(formatted_date)  # Output: Monday, May 14, 2024

And with a timestamp

import datetime

# Assume 'timestamp' is your integer timestamp
timestamp = 1710403200  # Example timestamp for May 14, 2024

# Convert the integer timestamp to a datetime object
date_object = datetime.datetime.fromtimestamp(timestamp)

# Format the datetime object into a readable string
formatted_date = date_object.strftime('%A, %B %d, %Y')

print(formatted_date)  # Output: Tuesday, May 14, 2024

import datetime

# Assume 'timestamp' is your integer timestamp
timestamp = 1710403200  # Example timestamp for May 14, 2024

# Convert the integer timestamp to a datetime object in local time
date_object = datetime.datetime.fromtimestamp(timestamp, datetime.timezone.utc).astimezone()

# Format the datetime object into a readable string
formatted_date = date_object.strftime('%A, %B %d, %Y')

print(formatted_date)  # Output will reflect the local time equivalent of the given timestamp

import datetime

# Assume 'timestamp' is your integer timestamp
timestamp = 1710403200  # Example timestamp for May 14, 2024

# Convert the integer timestamp directly to a datetime object in local time
date_object = datetime.datetime.fromtimestamp(timestamp)

# Format the datetime object into a readable string
formatted_date = date_object.strftime('%A, %B %d, %Y')

print(formatted_date)  # Output: Tuesday, May 14, 2024 (adjusted for local timezone)

from timezone get friendly time stamp

self.x_post_dt =  time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(self.created_dt))