Groovy web console

subscribe to the feed Subscribe
to this
site
Date String to epoch time (via #groovywebconsole)
tweet this snippet Tweet
this
script

Date String to epoch time

Published 4 months ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import java.text.SimpleDateFormat
import java.util.concurrent.TimeUnit

String dateStr = "05.08.2017 21:20:00"
String tzStr = "PST"

printTimestamp("05.08.2017 21:20:00", "PST")
printTimestamp("06.08.2017 01:30:00", "PST")

def printTimestamp(String dateStr, String tzStr){
   SimpleDateFormat fmt = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss")
   def tz = TimeZone.getTimeZone(tzStr)
   fmt.setTimeZone(tz)

   def date = fmt.parse(dateStr)
   println "$dateStr -> ${TimeUnit.MILLISECONDS.toSeconds(date.time)} secs"
}