senthil kumar p senthil kumar p - 1 year ago 101
Scala Question

How to convert string to epoch time?

I have one column its has epoch time( String type) in the table.Want to minus one hour from epoch time .I'm trying to convert a string into epoch time and do the minus. But I am unable to convert the string to epoch time. Any help, please?

for Eg:

val epochTime="1499013460"

I want ti subtract one hour from the above epoch time.


Answer Source

If you have an epoch time values and all you want to do is to subtract an hour from it you can go with the simplest solution possible which is:

val secondsPerHour = 60 * 60
val withHourSubtracted = (epochTime.toLong - secondsPerHour).toString
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download