pyspark - 如何解析时间戳值并更改时间戳值
问题描述
给定这个时间戳值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
希望这对你有用
推荐阅读
- arrays - 哪种方法更好,每次保存值或评估?
- swift - Swift 3 Alamofire 请求进度
- zapier - Zapier Cli - 在 outputFields 上设置选项确实显示值,而不是显示文本
- android - 从 android studio 生成 singed APK 的错误显示
- python - 如何将 self 参数设置为装饰器?
- botframework - 如果使用 QnAMakerRecognizer.recognize 方法调用它,如何在 QnA 制造商中添加阈值
- python - Python Pandas:多个聚合 -> 值列表
- ruby-on-rails - 在记录创建时跳过回调
- spring - 尝试在spring-boot上启动jpa时如何解决错误消息?
- racket - 我可以在球拍中制作操作系统级别的键盘绑定吗?