Search code examples
pythoncasting

how to convert comma separated string to comma seperated int in python


i'm trying to convert any timezone time to uk time. i'm getting the value error in the time_format variable.

from datetime import datetime
from pytz import timezone

newyork_tz = timezone('America/New_York')
london_tz = timezone('Europe/London')

it is in type string and when i'm trying to convert to int it is giving me this error

ValueError: invalid literal for int() with base 10: '2022, 02, 02, 21, 32, 25'

expecting out like below with type int

2022, 02, 02, 21, 28, 15

i'm new to python plz guide me with possible solution


Solution

  • Use strptime() to parse a datetime. It uses the same format string as strftime().

    newyork = newyork_tz.localize(datetime.strptime(time_format, format))