How to convert unix timestamp to date in Spark

前端 未结 7 1708
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 11:42

I have a data frame with a column of unix timestamp(eg.1435655706000), and I want to convert it to data with format \'yyyy-MM-DD\', I\'ve tried nscala-time but it doesn\'t w

7条回答
  •  遥遥无期
    2020-12-01 12:43

    Here it is using Scala DataFrame functions: from_unixtime and to_date

    // NOTE: divide by 1000 required if milliseconds
    // e.g. 1446846655609 -> 2015-11-06 21:50:55 -> 2015-11-06 
    mr.select(to_date(from_unixtime($"ts" / 1000))) 
    

提交回复
热议问题