Home > Software design >  Convert paypal date to string in python
Convert paypal date to string in python

Time:03-15

paypal is giving me this format '03:00:00 Mar 14, 2023 PDT'. I've tried different solutions but i can't get with the right one. How can i separate each item into a string using python?

CodePudding user response:

Assuming you want a datetime object

from datetime import datetime

time_string = "03:00:00 Mar 14, 2023 PDT"
d = datetime.strptime(time_string[:-4], "%H:%M:%S %b %d, %Y")

or

import parsedatetime as pdt # $ pip3 install parsedatetime
cal = pdt.Calendar()

time_string = "03:00:00 Mar 14, 2023 PDT"
d = cal.parseDT(time_string)[0]

Once you have your datetime, output the part(s) you want using strftime

  • Related