spark日期格式转换

object FilterUtilsV4{

  //如果object使用了成员变量,那么会出现线程安全问题,因为object是一个单例,多线程可以同时调用这个方法
  //E代表星期几
  //val dateFormat = new SimpleDateFormat("yyyy年MM月dd日,E,HH:mm:ss")
  //FastDateFormat是线程安全的
  val dateFormat = FastDateFormat.getInstance("yyyy年MM月dd日,E,HH:mm:ss")

  def filterByTime(fields: Array[String], startTime: Long, endTime: Long) = {
    val time = fields(1)
    val timeLong = dateFormat.parse(time).getTime
    timeLong >= startTime && timeLong < endTime
  }
}

猜你喜欢

转载自blog.csdn.net/hanyong4719/article/details/83274442
今日推荐