Java Today today()

Here you can find the source of today()

Description

today

License

Open Source License

Declaration

public static Date today() 

Method Source Code


//package com.java2s;

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 final String DATE_FORMAT = "yyyy/MM/dd";

    public static Date today() {
        try {//from  w w  w . j av a2  s .  c om
            return new SimpleDateFormat(DATE_FORMAT).parse(formatDate(new Date()));
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String formatDate(Date d) {
        return format(d, DATE_FORMAT);
    }

    public static String format(Date d, String format) {
        return format(d, format, Locale.getDefault());
    }

    public static String format(Date d, String format, Locale locale) {
        if (d == null)
            return "";
        DateFormat df = new SimpleDateFormat(format, locale);
        return df.format(d);
    }
}

Related

  1. today()
  2. today()
  3. today()
  4. today()
  5. today()
  6. today()
  7. toDay(final String dateString)
  8. today(String format)
  9. today(String pattern)