Python Forum
Change Time Format in Python
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?
Reply
#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.
Reply
#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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python date format changes to date & time 1418 4 518 Jan-20-2024, 04:45 AM
Last Post: 1418
  How to change UTC time to local time in Python DataFrame? SamKnight 2 1,527 Jul-28-2022, 08:23 AM
Last Post: Pedroski55
  What time format is this? wrybread 3 1,991 Jun-15-2022, 02:46 PM
Last Post: snippsat
Smile Set 'Time' format cell when writing data to excel and not 'custom' limors 3 6,203 Mar-29-2021, 09:36 PM
Last Post: Larz60+
  how to change the range of read CSV file every time python file runs greenpine 6 4,382 Dec-08-2020, 10:11 PM
Last Post: greenpine
  ValueError: time data 'None' does not match format '%Y-%m-%dT%H:%M:%S.%f' rajesh3383 4 14,199 Sep-03-2020, 08:22 PM
Last Post: buran
  how to retain time format in df.to_csv Mekala 2 3,070 Aug-07-2020, 07:04 AM
Last Post: buran
  getting error ValueError: time data '' does not match format '%H:%M' srisrinu 2 5,549 Apr-09-2020, 11:12 AM
Last Post: srisrinu
  make a list of the file in the folder and change the name of file regarding to time go127a 5 2,886 Feb-21-2020, 10:36 AM
Last Post: go127a
  openpyxl, if value in cell then change format genderbee 1 5,181 Nov-05-2019, 01:37 PM
Last Post: genderbee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020