Java tutorial
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static SimpleDateFormat sf; public static long getStringToDate(String time, String format) { if (format != null) { sf = new SimpleDateFormat(format); } else { sf = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); } Date date = new Date(); try { date = sf.parse(time); } catch (ParseException e) { e.printStackTrace(); } return date.getTime(); } }