gpt4 book ai didi

pyspark - to_timestamp 什么时候从 19xx 产生结果?

转载 作者:行者123 更新时间:2023-12-04 10:53:13 26 4
gpt4 key购买 nike

PySpark 在什么条件/标准下以 dd-MMM-yy 格式转换日期(01-JAN-40) 至 1940-01-01 00:00:00.000而不是 2040-01-01 00:00:00.000 ?

from pyspark.sql import functions as psf
df.withColumn('my_date', psf.to_timestamp("my_date", "dd-MMM-yy"))

我运行的一些示例如下:
01-JAN-40 -> 1940-01-01 00:00:00.000
01-JAN-47 -> 1947-01-01 00:00:00.000
01-JAN-15 -> 2015-01-01 00:00:00.000
01-JAN-18 -> 2018-01-01 00:00:00.000
01-JAN-19 -> 2019-01-01 00:00:00.000
01-JAN-20 -> 2020-01-01 00:00:00.000

最佳答案

目前(Spark <= 2.4.4),spark 正在使用 java SimpleDateFormat引擎盖下的类来解析字符串。来自 java 文档 here , 规定

For parsing with the abbreviated year pattern ("y" or "yy"), SimpleDateFormat must interpret the abbreviated year relative to some century. It does this by adjusting dates to be within 80 years before and 20 years after the time the SimpleDateFormat instance is created.



因此,如果您在 2019 年运行它,则最多 39 的所有内容都将在 20xx 中,其他所有内容都将在 19xx 中

关于pyspark - to_timestamp 什么时候从 19xx 产生结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59365446/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com