1

I have a python datetime object that I want to display on a website, however the time shows in the format hh:mm:ss and I want to display it in the format hh:mm.

I have tried using the replace method as per the following:

message.timestamp.replace(second='0', microsecond=0)

However this doesn't get red of the seconds it just replaces it with hh:mm:00

r0ss26
  • 27
  • 1
  • 1
  • 4

1 Answers1

10

Use strftime() function

>>> from datetime import datetime
>>> datetime.now()
datetime.datetime(2018, 12, 27, 11, 14, 37, 137010)
>>> now = datetime.now()
>>> now.strftime("%H:%M")
'11:15'
Aravind
  • 534
  • 1
  • 6
  • 18