Java Today getTodayAsLong()

Here you can find the source of getTodayAsLong()

Description

Liefert das heutige Datum als long

License

Open Source License

Declaration

public static long getTodayAsLong() 

Method Source Code

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

import java.util.Calendar;

import java.util.GregorianCalendar;
import java.util.TimeZone;

public class Main {
    /**/*from   ww w .  j a  va2  s .c  o  m*/
     * Liefert das heutige Datum als long
     * 
     * @return
     */
    public static long getTodayAsLong() {
        long ret = 0;

        GregorianCalendar calToday = new GregorianCalendar(TimeZone.getTimeZone("Europe/Berlin"));
        calToday.setFirstDayOfWeek(Calendar.SUNDAY);

        try {
            ret = getDateAsLong(calToday.getTime());
        } catch (NumberFormatException e) {
        }

        return ret;
    }

    public static Long getDateAsLong(java.util.Date _date) {
        long ret = 0;

        GregorianCalendar calDatum = new GregorianCalendar(TimeZone.getTimeZone("Europe/Berlin"));
        calDatum.setFirstDayOfWeek(Calendar.SUNDAY);
        calDatum.setTime(_date);

        try {
            ret = Long.valueOf(calDatum.get(GregorianCalendar.YEAR) + ""
                    + fillTwoSigns((calDatum.get(GregorianCalendar.MONTH) + 1)) + ""
                    + fillTwoSigns(calDatum.get(GregorianCalendar.DAY_OF_MONTH)));
        } catch (NumberFormatException e) {
        }

        return ret;
    }

    public static String fillTwoSigns(int _number) {
        String ret = String.valueOf(_number);

        if (_number <= 9) {
            ret = "0" + ret;
        }

        return ret;
    }
}

Related

  1. getToday(int hour, int minute, int second)
  2. getToday(String datePattern)
  3. getToday(String format)
  4. getToday(String formatString)
  5. getToday(String time)
  6. getTodayAsSecond()
  7. getTodayDate()
  8. getTodayDate()
  9. getTodayDate()