Java Date Now getCurrentDay()

Here you can find the source of getCurrentDay()

Description

get Current Day

License

Open Source License

Return

yyyy-MM-dd

Declaration

public static String getCurrentDay() 

Method Source Code


//package com.java2s;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Iterator;
import java.util.Map;

public class Main {
    private static String DEFAULT_PATTERN = "yyyy-MM-dd";
    private static Map<String, SimpleDateFormat> formats;

    /**/*w ww  .j a v a2  s . com*/
     * @return  yyyy-MM-dd
     */
    public static String getCurrentDay() {
        return format(new Date(), DEFAULT_PATTERN);
    }

    /**
     * 
     * @param date
     *          
     * @param pattern
     *          
     * @return
     */
    public static String format(Date date, String pattern) {
        if (!formats.containsKey(pattern))
            pattern = DEFAULT_PATTERN;
        DateFormat format = formats.get(pattern);
        return format.format(date);
    }

    /**
     * @param date
     * @return  String
     */
    public static String format(Date date) {
        Iterator<SimpleDateFormat> iter = formats.values().iterator();
        while (iter.hasNext()) {
            return iter.next().format(date);
        }
        return null;
    }
}

Related

  1. getCurrentDateTimeStringValue()
  2. getCurrentDateToString(String pattern)
  3. getCurrentDateWithDot()
  4. getCurrentDay()
  5. getCurrentDay()
  6. getCurrentDay()
  7. getCurrentDay()
  8. getCurrentDay()
  9. getCurrentDay(int model)