Java Date Now currentDateStr(String format)

Here you can find the source of currentDateStr(String format)

Description

current Date Str

License

Open Source License

Declaration

public static String currentDateStr(String format) 

Method Source Code


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

import java.text.DateFormat;

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

public class Main {

    public static String currentDateStr(String format) {
        return toString(format, now());
    }//  w  w  w .ja va  2s . c  o  m

    public static String toString(String format, Date date) {
        if (format == null || format.isEmpty()) {
            return format;
        }
        if (date == null) {
            return null;
        }
        DateFormat dateFormat = new SimpleDateFormat(format);
        return dateFormat.format(date);
    }

    public static String toString(Date date, String format) {
        if (format == null || format.isEmpty()) {
            return format;
        }
        if (date == null) {
            return null;
        }
        DateFormat dateFormat = new SimpleDateFormat(format);
        return dateFormat.format(date);
    }

    public static Date now() {
        Calendar cal = Calendar.getInstance();
        return cal.getTime();
    }
}

Related

  1. currentDate2String()
  2. currentDate_DDMMYY()
  3. currentDateAsString()
  4. currentDatePath(String basePath)
  5. currentDateStr()
  6. currentDateString()
  7. currentDateTime(long time, int type)
  8. currentDateTimeMillis()
  9. currentDateTimeToEasySortedDateTime()