How to get the current local time or system time in spark-scala dataframe?

僤鯓⒐⒋嵵緔 提交于 2019-12-11 19:35:57

问题


I am trying to get the local time in spark-scala but it is returning UTC.

I am using java.time.LocalDateTime to get the current timestamp. But its returning the UTC standard.

java.sql.Timestamp.valueOf(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss.SSSSSS").format(LocalDateTime.now))

The LocalDateTime is returning local time in spark shell, but in my code it is giving UTC standard.

val time: LocalDateTime = LocalDateTime.now

How to get the current time?

The current output is UTC. I need the local time. I need to change the zone.


回答1:


Use current_timestamp() in org.apache.spark.sql.fuctions, this gives local time.



来源:https://stackoverflow.com/questions/58143743/how-to-get-the-current-local-time-or-system-time-in-spark-scala-dataframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!