Java Today getTodayDate()

Here you can find the source of getTodayDate()

Description

get Today Date

License

Open Source License

Declaration

public static Date getTodayDate() 

Method Source Code

//package com.java2s;

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

public class Main {
    public static Date getTodayDate() {
        Calendar cal = Calendar.getInstance();

        Calendar now = Calendar.getInstance();
        now.clear();/* w  ww .  ja va2  s . c  o m*/
        now.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
        return now.getTime();
    }

    public static String getTime(Calendar c) {
        return getDate(c.getTime(), "HH:mm:ss");
    }

    public static String getDate() {
        return getDate(getCurDate(), "yyyy-MM-dd");
    }

    public static String getDate(Date date, String format) {

        String dtstr = "";
        if (date == null) {
            return dtstr;
        }

        if (format == null || "".equals(format.trim())) {
            format = "yyyy-MM-dd";
        }

        SimpleDateFormat sdf = new SimpleDateFormat(format);
        dtstr = sdf.format(date);
        return (dtstr == null ? "" : dtstr);

    }

    public static String getDate(Date date) {
        return getDate(date, "yyyy-MM-dd");
    }

    public static Date getDate(long time) {

        Calendar c = getCurCalendar();
        c.setTimeInMillis(time);

        return c.getTime();
    }

    public static Date getCurDate() {
        return getCurCalendar().getTime();
    }

    public static Calendar getCurCalendar() {
        return Calendar.getInstance();
    }
}

Related

  1. getToday(String format)
  2. getToday(String formatString)
  3. getToday(String time)
  4. getTodayAsLong()
  5. getTodayAsSecond()
  6. getTodayDate()
  7. getTodayDate()
  8. getTodayDateAsString()
  9. getTodayDateInString()