0

I have a datetime from below generated code

from datetime import datetime
from pytz import timezone
tz = timezone('US/Pacific')
print(datetime.now(tz)) # 2019-06-17 05:41:22.189735-07:00

I am looking for this format of output

"Wed, 17 Jun 2019 05:41:22 -0700"

How can i achieve this?

Ashwin S
  • 165
  • 2
  • 11

2 Answers2

1

You're looking for the datetime.strftime method:

print(datetime.now().strftime("%a, %d %b %Y %H:%M:%S.%f"))
olinox14
  • 6,177
  • 2
  • 22
  • 39
0

i managed to fix it myself by

print(datetime.now(tz).strftime("%a, %d %B %Y %H:%M:%S %z")) # Mon, 17 June 2019 05:51:16 -0700
Ashwin S
  • 165
  • 2
  • 11