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
  Incorrect time format KoSik 5 119 Aug-15-2019, 05:10 PM
Last Post: KoSik
  changing format to Int Scott 3 271 Jun-19-2019, 06:33 AM
Last Post: ODIS
  Date format issue the_dude 11 731 Jun-07-2019, 06:27 AM
Last Post: snippsat
  Changing Number Format moby 4 228 May-24-2019, 11:04 PM
Last Post: snippsat
  changing { and } in str.format() Skaperen 10 519 May-16-2019, 05:07 AM
Last Post: Skaperen
  error: self.name = "NPC{}".format(num_of_NPCs + 1) Exsul 1 148 May-03-2019, 08:56 PM
Last Post: ichabod801
  Why does time.sleep(wait) add time in python3 ? gerardg 4 498 Apr-28-2019, 06:26 PM
Last Post: gerardg
  Format for elif sunilramakumar 4 357 Apr-08-2019, 05:21 PM
Last Post: Yoriz
  Help regarding date format Prince_Bhatia 2 235 Apr-01-2019, 05:46 AM
Last Post: Prince_Bhatia
  Is it possible to have my python shell change the backgrounds colour? OTO1012 2 309 Mar-07-2019, 09:32 PM
Last Post: woooee

Forum Jump:


Users browsing this thread: 1 Guest(s)