Created
December 5, 2016 07:37
-
-
Save tush4r/ee08f7f98d24c61a13203c636df144b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.joda.time.format.DateTimeFormat | |
import org.joda.time.{DateTime, DateTimeZone} | |
import scala.util.Try | |
object TimeStampUtility { | |
def getCurrentTimeStamp(): Long = { | |
val timestamp: Long = System.currentTimeMillis / 1000 | |
timestamp | |
} | |
def isGreaterThanCurrentTimeStamp(timestamp:Long): Boolean = { | |
val currentTimestamp: Long = getCurrentTimeStamp().toLong | |
val isGivenTimeStampValid = Try(timestamp.toLong).isSuccess | |
var booleanTimeStamp = false | |
if (isGivenTimeStampValid) { | |
if (currentTimestamp < timestamp.toLong) { | |
booleanTimeStamp = true | |
} | |
} | |
booleanTimeStamp | |
} | |
def addToCurrentTimeStamp(timeInSeconds:Long): Long = { | |
val currentTimeStamp = getCurrentTimeStamp() | |
val newTimeStamp = timeInSeconds + currentTimeStamp | |
newTimeStamp | |
} | |
def convertEpochToDateTime(epochTimeInSeconds:Long): String = { | |
val currentTimeZone = DateTimeZone.getDefault() | |
val currentEpoch = getCurrentTimeStamp() | |
val currentTime = DateTimeFormat.forPattern("YYYY-MM-dd HH:mm:ss").print(currentEpoch*1000) | |
currentTime | |
} | |
def convertDateTimeToEpoch(dateTime_YYYY_MM_dd_HH_mm_SS:String): Long = { | |
val date = DateTimeFormat.forPattern("YYYY-MM-dd HH:mm:ss").parseDateTime(dateTime_YYYY_MM_dd_HH_mm_SS) | |
date.getMillis | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment