Pyspark 如何解析时间戳值并更改时间戳值

Pyspark 如何解析时间戳值并更改时间戳值,pyspark,timestamp,unix-timestamp,Pyspark,Timestamp,Unix Timestamp,给定此时间戳值2019-01-29T16:22:54+00:00(此格式为YYYY-MM DDThh:MM:ss±hh:MM) 我需要将最后一个00:00(对应于hh:mm)更改为“Z”检查下面的简单示例,您可以根据您的更多要求进行调整 def convert_z_time(time_string): if time_string[-5:] == '00:00': converted_time = '{}Z'.format(time_string[:-6]) el

给定此时间戳值2019-01-29T16:22:54+00:00(此格式为YYYY-MM DDThh:MM:ss±hh:MM)


我需要将最后一个00:00(对应于hh:mm)更改为“Z”

检查下面的简单示例,您可以根据您的更多要求进行调整

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))
输出应该是

2019-01-29T16:22:54Z
2019-01-29T16:22:54+10:00

希望它对你有用。是什么阻止了你?我不知道怎么做基本上,我应该找到一种方法通过日期检查来解析,如果hh:mm等于00:00,如果它的真正变化是字母“Z”,那么,你是python的,并且这个日期是字符串,对吗?你有没有想过用“Z”替换最后6个字符<代码>myVar='2019-01-29T16:22:54+00:00';打印(myVar[:19]+“Z”)在我的操场上工作。那是数据帧吗?请将df.printSchema()的输出添加到您的问题中。yea是一个具有列Time的数据帧,其中包含2019-01-29T16:22:54+00:00格式的时间戳日期。但每次有+00:00,我都需要用Z来代替它。