Given this timestamp value 2019-01-29T16:22:54+00:00 (in this format YYYY-MM-DDThh:mm:ss±hh:mm)
I need to change the last 00:00 (corresponding to hh:mm) into a 'Z'
Check simple sample below, you can adjust it for your more requirement
def convert_z_time(time_string):
if time_string[-5:] == '00:00':
converted_time = '{}Z'.format(time_string[:-6])
else:
converted_time = time_string
return converted_time
time_string = '2019-01-29T16:22:54+00:00'
print(convert_z_time(time_string))
time_string = '2019-01-29T16:22:54+10:00'
print(convert_z_time(time_string))
The output should be
2019-01-29T16:22:54Z
2019-01-29T16:22:54+10:00
Hope it works for you