Java Date to Long formatDateToLong(String strDate, String formatstr)

Here you can find the source of formatDateToLong(String strDate, String formatstr)

Description

format Date To Long

License

Open Source License

Declaration

public static long formatDateToLong(String strDate, String formatstr) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static long formatDateToLong(String strDate, String formatstr) {
        if (strDate == null || "".equals(strDate.trim()) || "0".equals(strDate)) {
            return 0;
        }/*from w  w w .j av a 2s .  c o  m*/
        try {
            SimpleDateFormat sfarmat = new SimpleDateFormat(formatstr);
            Date date = sfarmat.parse(strDate);
            return date.getTime() / 1000;
        } catch (Exception e) {
            return 0;
        }
    }
}

Related

  1. dateToLong(Date date)
  2. dateToNumber(Date date)
  3. formatDateLong(Date date, Locale locale)
  4. formatDateToLong(Date date, String format)