Java tutorial
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { public static int getTimestamp(String targetTime, long currentTime) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar cal = Calendar.getInstance(); cal.setTime(sdf.parse(targetTime)); long time1 = cal.getTimeInMillis(); long between_days = (time1 - currentTime) / (1000 * 3600 * 24); return Integer.parseInt(String.valueOf(between_days)); } }