Java Today getTodayStr()

Here you can find the source of getTodayStr()

Description

getToday get todat string with format YYYY-MM-DD from a Date object

License

Open Source License

Parameter

Parameter Description
date date

Return

String

Declaration


static public String getTodayStr() throws ParseException 

Method Source Code

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

import java.text.ParseException;

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

public class Main {
    /**//from  ww  w. j  av  a2 s.co m
     * format pattern : yyyy-MM-dd
     */
    public static final SimpleDateFormat FORMAT_YYYY_MM_DD = new SimpleDateFormat("yyyy-MM-dd");

    /**
     * getToday get todat string with format YYYY-MM-DD from a Date object
     * 
     * @param date
     *            date
     * @return String
     */

    static public String getTodayStr() throws ParseException {
        Calendar calendar = Calendar.getInstance();
        return getDateStr(calendar.getTime());
    }

    /**
     * getDateStr get a string with format YYYY-MM-DD from a Date object
     * 
     * @param date
     *            date
     * @return String
     */
    static public String getDateStr(Date date) {
        return FORMAT_YYYY_MM_DD.format(date);
    }

    static public String format(Date date, String formatText) throws Exception {
        SimpleDateFormat format = new SimpleDateFormat(formatText);
        return format.format(date);
    }
}

Related

  1. getTodayMin()
  2. getTodayNight()
  3. getTodaysDate()
  4. getTodaysDate(String dateFormat)
  5. getTodayStart()
  6. getTodayStr()
  7. getTodayString()
  8. getTodayString()
  9. getTodayString()