Python Forum

Full Version: Change Time Format in Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys,

I'm trying to change the date format of when an AWS server was launched into something more readable for the user.

I'm getting this error:
Error:
Traceback (most recent call last): File ".\aws_ec2_terminate_instances.py", line 47, in <module> datetime(launch_time) TypeError: an integer is required (got type datetime.datetime)
And this is my code:
import datetime
from datetime import datetime
instance = ec2.describe_instances(
	InstanceIds=[instance_id]
	)['Reservations'][0]['Instances'][0]   
launch_time = instance['LaunchTime']
datetime(launch_time)
launch_time_friendly = launch_time.strftime("%B %d %Y")
print("Server was launched at: ", launch_time_friendly)
This is the value of launch_time:
2019-03-04 19:13:20+00:00
How can I go about this in the correct way?
Line 7 doesn't actually do anything. It tries to create a datetime instance and then discards it.
Simply removing that line should work.
(Mar-04-2019, 08:40 PM)stranac Wrote: [ -> ]Line 7 doesn't actually do anything. It tries to create a datetime instance and then discards it.
Simply removing that line should work.
Ok thanks! That does work when I remove the line. Appreciate the help!