Java Date to String DateToInteger(Date date)

Here you can find the source of DateToInteger(Date date)

Description

Date To Integer

License

Open Source License

Declaration


public static Long DateToInteger(Date date) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;

public class Main {

    public static Long DateToInteger(Date date) {
        SimpleDateFormat f = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
        String t = date.toString();
        Long dateLong = null;//from   w ww .j av  a 2 s.c o m
        try {
            Date d = f.parse(t);
            dateLong = d.getTime() / 1000;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return dateLong;
    }

    public static Date parse(String source, String format) throws ParseException {
        if (source == null) {
            return null;
        }

        DateFormat df = null;
        if (format != null) {
            df = new SimpleDateFormat(format);
        } else {
            df = DateFormat.getDateInstance(DateFormat.DEFAULT);
        }

        return df.parse(source);

    }

    public static String getTime(Date dt, String format) {
        SimpleDateFormat st = new SimpleDateFormat(format);
        return st.format(dt);
    }
}

Related

  1. dateToFormattedString(Date toFormat)
  2. dateToHHmmStr(Date date)
  3. dateToHMTime(Date date)
  4. dateToHttpDateString(Date d)
  5. dateToHuman(Date date)
  6. dateToIso(Date d)
  7. dateToIso8601String(Date date)
  8. dateToISODate(Date date)
  9. dateToOracleDateString(Date date)