IOTUtils.scala 619 B

12345678910111213141516171819202122232425
  1. package com.persagy.iot.utils
  2. import java.text.SimpleDateFormat
  3. object IOTUtils {
  4. /**
  5. * 将时间字段转换成时间戳
  6. * @param dateStr 时间字段
  7. * @param formatPattern 要转换时间字段的格式
  8. * @param offer 时差(单位:毫秒)
  9. * @return
  10. */
  11. def timestampConverter(formatPattern: String, dateStr: String, offer: Long): Long ={
  12. val simpleDateFormat = new SimpleDateFormat(formatPattern)
  13. val timestamp = simpleDateFormat.parse(dateStr).getTime
  14. timestamp + offer
  15. }
  16. /**
  17. * 获取当前时间
  18. * @return
  19. */
  20. def now(): Long = {System.currentTimeMillis ()}
  21. }