Java Today today()

Here you can find the source of today()

Description

today

License

Apache License

Declaration

public static Date today() 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static Date today() {
        return clearTime(new Date());
    }//from  www . j  a  va 2 s .c  om

    public static Date clearTime(Date date) {
        return parseDate(format(date));
    }

    public static Date parseDate(String dateStr, String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        try {
            return sdf.parse(dateStr);
        } catch (Exception e) {
            return null;
        }
    }

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

    public static String format(Date date, String pattern) {
        if (date == null)
            return "";
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }

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

Related

  1. today()
  2. today()
  3. Today()
  4. today()
  5. today()
  6. today()
  7. today()
  8. today()
  9. today()