Since the question is tagged pandas
, I assume the strings with the time in it are part of a pd.Series
or pd.DataFrame
. Also note that you cannot associate a time to a time zone unambiguously if you don't have a date - just think about DST.
Similar to the other answers, in pandas you would extract time with a regex, parse to datetime and associate / change time zone / UTC:
import pandas as pd
df = pd.DataFrame({'strings':["I eat potato at 5:30 PM"]})
# add a date,
# extract the time with a suitable regex,
# parse to datetime
date = '2020-11-06 '
df['USEastern_dt'] = pd.to_datetime(date + df['strings'].str.extract('(\d{1,2}\:\d{2}\ [A-P]{2})')[0])
# localize to US/Eastern
df['USEastern_dt'] = df['USEastern_dt'].dt.tz_localize('US/Eastern')
# convert to UTC
df['UTC_dt'] = df['USEastern_dt'].dt.tz_convert('UTC')
...which would give you
df['UTC_dt']
0 2020-11-06 22:30:00+00:00
Name: UTC_dt, dtype: datetime64[ns, UTC]