All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.scalatra.util.DateUtil.scala Maven / Gradle / Ivy

The newest version!
package org.scalatra.util

import java.util.{ Locale, TimeZone, Date }
import java.text.SimpleDateFormat

object DateUtil {
  @volatile private[this] var _currentTimeMillis: Option[Long] = None
  def currentTimeMillis = _currentTimeMillis getOrElse System.currentTimeMillis
  def currentTimeMillis_=(ct: Long) = _currentTimeMillis = Some(ct)
  def freezeTime() = _currentTimeMillis = Some(System.currentTimeMillis())
  def unfreezeTime() = _currentTimeMillis = None
  def formatDate(date: Date, format: String, timeZone: TimeZone = TimeZone.getTimeZone("GMT"), locale: Locale = Locale.ENGLISH) = {
    val df = new SimpleDateFormat(format, locale)
    df.setTimeZone(timeZone)
    df.format(date)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy