scala将UTC时间格式化

 import java.text.SimpleDateFormat


  def transformDateUTC(str1:String)={
    var str3 = str1
    val format1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
    val format2 = new SimpleDateFormat("yyyyMMddHHmmss")
    var date = format1.parse(str3)
    var str2 = format2.format(date)

    str2
  }

transformDateUTC("2018-07-28T16:00:00.000Z")


结果:
transformDateUTC: (str1: String)String
res116: String = 20180728160000

  

也可以将

val format2 = new SimpleDateFormat("yyyyMMddHHmmss")

更改为自己想要的格式如:“yyyyMMdd”, “yyyy-MM-dd HH:mm:ss”

你可能感兴趣的:(Scala,Spark)