Java Date Now getCurrentDate(String format)

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

Description

get Current Date

License

Educational Community License

Declaration

public static String getCurrentDate(String format) 

Method Source Code

//package com.java2s;
/*//from  w w  w. ja v a2s.c o  m
 * Copyright 2014 University of Washington
 *
 * Licensed under the Educational Community License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl1.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */

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

public class Main {
    public static final long MILLISECONDS_IN_ONE_DAY = 24 * 60 * 60 * 1000;

    public static String getCurrentDate() {
        return getDate(0);
    }

    public static String getCurrentDate(String format) {
        return getDate(0, format);
    }

    public static String getDate(int days, String format) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        Date dt = new Date();
        dt.setTime(dt.getTime() + days * MILLISECONDS_IN_ONE_DAY);
        return dateFormat.format(dt);
    }

    public static String getDate(int days) {
        return getDate(days, "MM/dd/yyyy"); // default date format
    }
}

Related

  1. getCurrentDate()
  2. getCurrentDate(boolean WithDelimeter)
  3. getCurrentDate(Date date)
  4. getCurrentDate(final String form)
  5. getCurrentDate(final String FORMAT)
  6. getCurrentDate(String format)
  7. getCurrentDate(String format)
  8. getCurrentDate(String format)
  9. getCurrentDate(String format)