Java Today todaysDate(int style)

Here you can find the source of todaysDate(int style)

Description

Get today's date in various formats style=0 -> ddMMyyyy style=1 -> YYYY-MM-dd style=2 -> dd-MMM-YYY

License

Open Source License

Declaration

public static String todaysDate(int style) throws Throwable 

Method Source Code


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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**/*from  www .  j a  v a 2  s . c  o m*/
     * Get today's date in various formats 
     * style=0 -> ddMMyyyy
     * style=1 -> YYYY-MM-dd
     * style=2 -> dd-MMM-YYY
     */
    public static String todaysDate(int style) throws Throwable {
        Date date = new Date();
        SimpleDateFormat formatterOut = null;
        //
        if (style == 0) {
            formatterOut = new SimpleDateFormat("ddMMMyyyy");
        } else if (style == 1) {
            formatterOut = new SimpleDateFormat("yyyy-MM-dd");
        } else if (style == 2) {
            formatterOut = new SimpleDateFormat("dd-MMM-yyyy");
        } else {
            throw new RuntimeException("Invalid date style");
        }
        return formatterOut.format(date);
    }
}

Related

  1. todayAtDayEnd()
  2. todayDate()
  3. todayMinute()
  4. todayPlusDays(int days)
  5. toDaysBeforeOrAfter(Date date, Integer days)
  6. todaySortedTimestamp()
  7. todayStart()
  8. todaysTime()
  9. todayStr()