Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Change Time Format in Python
#1
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?
Quote
#2
Line 7 doesn't actually do anything. It tries to create a datetime instance and then discards it.
Simply removing that line should work.
Quote
#3
(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!
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  openpyxl, if value in cell then change format genderbee 1 159 Nov-05-2019, 01:37 PM
Last Post: genderbee
  Incorrect time format KoSik 5 293 Aug-15-2019, 05:10 PM
Last Post: KoSik
  Change format of datetime Jonas85 6 597 Feb-05-2019, 03:47 PM
Last Post: Jonas85
  Getting error in finding time.time() value in python Lakshana 1 799 Jan-11-2018, 07:07 AM
Last Post: wavic
  Reading and writing to text file has format change cheerful 3 1,025 Dec-21-2017, 07:53 AM
Last Post: Larz60+
  python data format to c data format tony1812 1 854 Dec-02-2017, 12:34 AM
Last Post: Larz60+
  Wrong or missing date format and time in mails sipriusPT 3 994 Aug-08-2017, 03:22 PM
Last Post: sipriusPT

Forum Jump:


Users browsing this thread: 1 Guest(s)