How to convert a string Date to long millseconds
问题 I have a date inside a string, something like \"12-December-2012\". How can I convert this into milliseconds (long)? 回答1: Using SimpleDateFormat String string_date = "12-December-2012"; SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yyyy"); try { Date d = f.parse(string_date); long milliseconds = d.getTime(); } catch (ParseException e) { e.printStackTrace(); } 回答2: SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy"); Date date = (Date)formatter.parse("12-December-2012"); long