Home:ALL Converter>Groovy: How to get unix time of a certain date instead of current Date?

Groovy: How to get unix time of a certain date instead of current Date?

Ask Time:2021-01-19T21:58:14         Author:Tobitor

Json Formatter

I have this code:

Date toDate = new Date();
Date fromDate = toDate - 30
long unixToTime = currentDate.getTime() / 1000
long unixFromDate = fromDate.getTime() / 1000

With this code I get the unix Time for the current Date and the unix Time for a date 30 days before. What I instead want is to get a code, where I can enter a specific toDate (e.g. 31-12-2020, 10:00:00) and then get the unix time of this instead.

Note: I am an absolute beginner regarding groovy.

Author:Tobitor,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/65792972/groovy-how-to-get-unix-time-of-a-certain-date-instead-of-current-date
yy