Java Second Format getMisSecond(String strDate)

Here you can find the source of getMisSecond(String strDate)

Description

get Mis Second

License

Open Source License

Declaration

public static long getMisSecond(String strDate) 

Method Source Code


//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static long getMisSecond(String strDate) {

        return getDate(strDate, "yyyy-MM-dd HH:mm:ss").getTime();

    }/* w  ww  .j a  va 2s  .  co  m*/

    public static long getTime(Date dateParam) {
        if (dateParam == null) {
            throw new IllegalArgumentException("The dateParam  must not be null");
        }
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(dateParam.getTime());

        int hour = cal.get(Calendar.HOUR);
        int minute = cal.get(Calendar.MINUTE);
        int second = cal.get(Calendar.SECOND);

        long result = hour * 3600 * 1000 + minute * 60 * 1000 + second * 1000;

        return result;
    }

    public static int getDate(Date dateParam) {
        if (dateParam == null) {
            throw new IllegalArgumentException("The dateParam  must not be null");
        }
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(dateParam.getTime());
        return cal.get(Calendar.DAY_OF_MONTH);
    }

    public static Date getDate(String strDate, String format) {
        if (strDate == null || format == null) {
            throw new IllegalArgumentException("The strDate or  the format must not be null");
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);

        try {
            return dateFormat.parse(strDate);
        } catch (Exception e) {
            e.printStackTrace();
            return new Date();
        }
    }

    public static Date getDate(String strDate) {
        return getDate(strDate, "yyyy-MM-dd HH:mm:ss");
    }
}

Related

  1. getFormatMSecond(long long_)
  2. getFormattedDuration(int simTimeSeconds)
  3. getFullDateByMisSecond(long misSecond)
  4. getFutureDate(int seconds)
  5. getIntervalMilSeconds(String startDateStr, String endDateStr, String dateFormat)
  6. getSecond()
  7. getSecond()
  8. getSecond()
  9. getSecond(Date date)