If you have a Date
type already, it's as simple as:
(System.currentTimeMillis() - myDate.getTime()) / 1000;
If you have a string and need to convert it to a date, you use a SimpleDateFormat
instance:
String dateString = "2015-02-21 13:00:00" // end_date_time
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
Date myDate = sdf.parse(dateString);
If you're using Java8, this is much easier:
String dateString = "2007-12-03T10:15:30.00Z";
Instant.now().until(Instant.parse(dateString), ChronoUnit.SECONDS);
Your dateString
must be parseable in the ISO format, though:
"yyyy-mm-ddThh:mm:ss.SZ"