How to convert unix timestamp to date in Spark

前端 未结 7 1715
伪装坚强ぢ
伪装坚强ぢ 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

    I have solved this issue using the joda-time library by mapping on the DataFrame and converting the DateTime into a String :

    import org.joda.time._
    val time_col = sqlContext.sql("select ts from mr")
                             .map(line => new DateTime(line(0)).toString("yyyy-MM-dd"))
    

提交回复
热议问题