Or, maybe you know a better approach how to solve this problem. I get dates in the format of \"YYYY—MM-DD HH:MM:SS\" and need to calculate time difference between now then i
First you need to parse your date string to a Date
and then get the timestamp from that:
final SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
final String myDateString = "someDateString";
final Date date = dateFormat.parse(myDateString);
final long timestamp = date.getTime();
Have a look at the SimpleDateFormat javadocs for information on which format string to use.