Java Date Now getCurrentDate(String formatStr)

Here you can find the source of getCurrentDate(String formatStr)

Description

get Current Date

License

BSD License

Declaration

public static String getCurrentDate(String formatStr) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright Duke Comprehensive Cancer Center and SemanticBits
 * /*w w w. j  a v a  2  s  . c  o m*/
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/c3pr/LICENSE.txt for details.
 ******************************************************************************/

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final String DISPLAY_DATE_FORMAT = "MM/dd/yyyy";

    public static String getCurrentDate(String formatStr) {
        // This is temporary fix, lot of places in the code the dateformat is coded as mm/dd/yyyy
        // instead of MM/dd/yyyy.
        if ("mm/dd/yyyy".equals(formatStr)) {
            formatStr = DISPLAY_DATE_FORMAT;
        }

        SimpleDateFormat formatter = new SimpleDateFormat(formatStr);
        Date currentDate = new Date();
        return formatter.format(currentDate);
    }
}

Related

  1. getCurrentDate(String format)
  2. getCurrentDate(String format)
  3. getCurrentDate(String format)
  4. getCurrentDate(String format)
  5. getCurrentDate(String format)
  6. getCurrentDate(String pattern)
  7. getCurrentDate(String pattern)
  8. getCurrentDate(String pattern)
  9. getCurrentDate(String pattern, Locale locale)