如何在Spark-Scala数据帧中获取当前本地时间或系统时间? [英] How to get the current local time or system time in spark-scala dataframe?
本文介绍了如何在Spark-Scala数据帧中获取当前本地时间或系统时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取Spark-scala中的本地时间,但它正在返回UTC.
I am trying to get the local time in spark-scala but it is returning UTC.
我正在使用java.time.LocalDateTime来获取当前时间戳.但是它恢复了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))
LocalDateTime在Spark Shell中返回本地时间,但是在我的代码中却给出了UTC标准.
The LocalDateTime is returning local time in spark shell, but in my code it is giving UTC standard.
val time: LocalDateTime = LocalDateTime.now
如何获取当前时间?
当前输出为UTC.我需要当地时间. 我需要更改区域.
The current output is UTC. I need the local time. I need to change the zone.
推荐答案
在org.apache.spark.sql.fuctions
中使用current_timestamp()
,这样可以提供本地时间.
Use current_timestamp()
in org.apache.spark.sql.fuctions
, this gives local time.
这篇关于如何在Spark-Scala数据帧中获取当前本地时间或系统时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文