Java Today todayDate()

Here you can find the source of todayDate()

Description

today Date

License

Open Source License

Declaration

static public String todayDate() 

Method Source Code


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

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    static public String todayDate() {
        Calendar now = Calendar.getInstance();
        now.setTime(new java.util.Date());
        return String.valueOf(now.get(Calendar.DAY_OF_MONTH)) + "-" + String.valueOf(now.get(Calendar.MONTH) + 1)
                + "-" + String.valueOf(now.get(Calendar.YEAR));
    }//ww  w.  j  a  v a  2s. co  m

    static public String todayDate(String format) {
        Calendar now = Calendar.getInstance();
        now.setTime(new java.util.Date());
        return date2String(now.getTime(), format);
    }

    public static String date2String(Date date) {
        if (date == null)
            return "";
        SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");

        return format.format(date);
    }

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

Related

  1. today(String pattern)
  2. today(String strFormat)
  3. todayAsSimpleIsoDate(Date date)
  4. todayAsXSDDateString()
  5. todayAtDayEnd()
  6. todayMinute()
  7. todayPlusDays(int days)
  8. toDaysBeforeOrAfter(Date date, Integer days)
  9. todaysDate(int style)