在Scala/Spark中将纪元转换为日期时间 [英] convert epoch to datetime in Scala / Spark
本文介绍了在Scala/Spark中将纪元转换为日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用:
def strToTime(x: String):Long = { DateTimeFormat.
forPattern("YYYY-MM-dd HH:mm:ss").parseDateTime(x).getMillis()/1000 }
获得像这样的Long列表:
to get a list of Long like this :
.map( p=> List( strToTime(p(0) ) ) )
我的问题是-向后上交的最简单方法是什么? 像这样:
my question is - what is the easiest way to turn in backwards? something like:
def timeToStr(x: Long):String = { x*1000L.toDateTime}
我可以在上面的列表(长)上使用的
that I could use on the above List(Long)
我已阅读将自纪元以来的秒数转换为Scala ,但无法成功应用
I have read Convert seconds since epoch to joda DateTime in Scala but can't apply it successfully
推荐答案
您有一个优先级问题-在应用*
之前将.toDateTime
应用于1000L
.用括号括起来以清楚显示呼叫顺序:
You have a precedence problem - .toDateTime
is being applied to 1000L
before *
is applied. Bracket the operations to make the call order clear:
def timeToStr(x: Long): String = { (x*1000L).toDateTime }
这篇关于在Scala/Spark中将纪元转换为日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文