Java Date to Long dateToNumber(Date date)

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

Description

date To Number

License

Open Source License

Declaration

public static final Long dateToNumber(Date date) 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {

    public static final Long dateToNumber(Date date) {
        if (date == null) {
            return null;
        }/*from  w  w w.  jav  a 2s. c o  m*/

        Calendar c = Calendar.getInstance();

        c.setTime(date);

        String month;
        String day;

        if ((c.get(Calendar.MONTH) + 1) >= 10) {
            month = "" + (c.get(Calendar.MONTH) + 1);
        } else {
            month = "0" + (c.get(Calendar.MONTH) + 1);
        }

        if (c.get(Calendar.DATE) >= 10) {
            day = "" + c.get(Calendar.DATE);
        } else {
            day = "0" + c.get(Calendar.DATE);
        }

        String number = c.get(Calendar.YEAR) + "" + month + day;

        return new Long(number);
    }
}

Related

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