Here you can find the source of getSecond(String time)
public static int getSecond(String time)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { public static int getSecond(String time) { String cc = "1970-01-01 00:00:00"; final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); final SimpleDateFormat sdf1 = new SimpleDateFormat("HH:mm:ss"); Calendar cal = Calendar.getInstance(); try {//from w ww . java 2s . c o m cal.setTime(sdf1.parse(time)); } catch (ParseException e) { e.printStackTrace(); } long aMillionSeconds = cal.getTimeInMillis(); try { cal.setTime(sdf.parse(cc)); } catch (ParseException e) { e.printStackTrace(); } long bMillionSeconds = cal.getTimeInMillis(); return (int) ((aMillionSeconds - bMillionSeconds) / (1000)); } }