Java Today getTodayString()

Here you can find the source of getTodayString()

Description

yyyyMMdd

License

Open Source License

Declaration

public static String getTodayString() 

Method Source Code


//package com.java2s;
import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public final static String shortFormat = "yyyyMMdd";

    /**//from w ww.  ja  v  a  2s .c  o m
     * yyyyMMdd
     * 
     * @return
     */
    public static String getTodayString() {
        DateFormat dateFormat = createNewDateFormat(shortFormat);
        return formatDateString(new Date(), dateFormat);
    }

    public static DateFormat createNewDateFormat(String pattern) {
        DateFormat df = new SimpleDateFormat(pattern);
        df.setLenient(false);
        return df;
    }

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

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

Related

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