Java Date Now getCurrentPlainDate()

Here you can find the source of getCurrentPlainDate()

Description

Get current date as string in format yyyymmdd

License

Mozilla Public License

Return

current date string in the format yyyymmdd

Declaration

public static String getCurrentPlainDate() 

Method Source Code

//package com.java2s;
/**/*  w w  w  .  j  a  v a2  s.co m*/
 * This Source Code Form is subject to the terms of the Mozilla Public License, 
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can 
 * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under 
 * the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
 * 
 * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS 
 * graphic logo is a trademark of OpenMRS Inc.
 */

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

public class Main {
    /**
     * Get current date as string in format yyyymmdd
     * 
     * @return current date string in the format yyyymmdd
     * @should return current date string in plain format
     */
    public static String getCurrentPlainDate() {
        return getPlainDateFrom(new Date());
    }

    /**
     * Get the date portion of a date as string in format yyyymmdd
     * 
     * @param date the date to extract the date portion from
     * @return date string in the format yyyymmdd
     * @should return date string in plain format for given date
     * @should return empty string given null
     */
    public static String getPlainDateFrom(Date date) {
        if (date == null) {
            return "";
        } else {
            SimpleDateFormat plainDateFormat = new SimpleDateFormat("yyyyMMdd");
            return plainDateFormat.format(date);
        }
    }
}

Related

  1. getCurrentMonthday()
  2. getCurrentMonthLastDay()
  3. getCurrentMonthStartTime()
  4. getCurrentMonthString(Calendar calendar)
  5. getCurrentODSDate()
  6. getCurrentQuarter()
  7. getCurrentSecond()
  8. getCurrentString(String pattern)
  9. getCurrentStringDate()