Java Second Format getSecond(String time)

Here you can find the source of getSecond(String time)

Description

get Second

License

Open Source License

Declaration

public static int getSecond(String time) 

Method Source Code


//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));
    }
}

Related

  1. getMisSecond(String strDate)
  2. getSecond()
  3. getSecond()
  4. getSecond()
  5. getSecond(Date date)
  6. getSeconds(long time)
  7. getSecondsFormatter()
  8. getSecondsSince(String rfc1123Date)
  9. getStringFromNanoSeconds(final long nanoSeconds, final long format)