Java Today getTodayDateAsString()

Here you can find the source of getTodayDateAsString()

Description

get the current date as string using the mysql date format yyyy-MM-dd

License

Mozilla Public License

Declaration

public static String getTodayDateAsString() 

Method Source Code

//package com.java2s;
/**/*from w w w.  j  ava 2s . c om*/
 * 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/.
 */

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

public class Main {
    public static final String mysqlDateFormat = "yyyy-MM-dd";

    /** 
     * get the current date as string using the mysql date format yyyy-MM-dd 
     **/
    public static String getTodayDateAsString() {
        // get a calendar instance, which defaults to "now"
        Calendar calendar = Calendar.getInstance();

        // get a date to represent "today"
        Date today = calendar.getTime();

        // get a SimpleDateFormat instance, passing the mysql date format as parameter
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(mysqlDateFormat);

        // return date as string
        return simpleDateFormat.format(today);
    }
}

Related

  1. getTodayAsLong()
  2. getTodayAsSecond()
  3. getTodayDate()
  4. getTodayDate()
  5. getTodayDate()
  6. getTodayDateInString()
  7. getTodayDbFormat()
  8. getTodayDisplayString()
  9. getTodayEnd()