Here you can find the source of converteDataStr2Long(String str)
public static long converteDataStr2Long(String str)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static long converteDataStr2Long(String str) { Date date = new Date(); String temp = str.substring(0, 4); date.setYear(Integer.valueOf(temp).intValue() - 1900); temp = str.substring(5, 7);/*from w ww.j a v a 2s . c o m*/ date.setMonth(Integer.valueOf(temp).intValue() - 1); temp = str.substring(8, 10); date.setDate(Integer.valueOf(temp).intValue()); temp = str.substring(11, 13); date.setHours(Integer.valueOf(temp).intValue()); temp = str.substring(14, 16); date.setMinutes(Integer.valueOf(temp).intValue()); temp = str.substring(17, 19); date.setSeconds(Integer.valueOf(temp).intValue()); return date.getTime() / 1000; } public static long getTime(String dateStr) { long time = -1; String format = "yyyy-MM-dd HH:mm:ss"; Date date = getDate(dateStr, format); if (date != null) { time = getDate(dateStr, format).getTime(); } return time; } public static Date getDate(String dateStr, String formatString) { Date date = null; try { SimpleDateFormat sdf = new SimpleDateFormat(formatString); date = sdf.parse(dateStr); } catch (Exception e) { e.printStackTrace(); } return date; } public static Date getDate(String dateStr) { return getDate(dateStr, "yyyy-MM-dd HH:mm:ss"); } }