Python Forum
Change Time Format in Python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Change Time Format in Python (/thread-16551.html)



Change Time Format in Python - bluethundr - Mar-04-2019

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?


RE: Change Time Format in Python - stranac - Mar-04-2019

Line 7 doesn't actually do anything. It tries to create a datetime instance and then discards it.
Simply removing that line should work.


RE: Change Time Format in Python - bluethundr - Mar-04-2019

(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!