Java Date Now getCurrentDateToString(String pattern)

Here you can find the source of getCurrentDateToString(String pattern)

Description

add by zhaoliguo format current date to string by input pattern

License

Open Source License

Parameter

Parameter Description
pattern a parameter

Return

String

Declaration

public static String getCurrentDateToString(String pattern) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**//from   www  .  j a  v a  2  s .co m
     * add by zhaoliguo format current date to string by input pattern
     * 
     * @param pattern
     * @return String
     */
    public static String getCurrentDateToString(String pattern) {
        Date date = new Date();
        return getDateToString(date, pattern);
    }

    /**
     * add by zhaoliguo format date to string by input pattern
     * 
     * @param date
     * @param pattern
     * @return String
     */
    public static String getDateToString(Date date, String pattern) {
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        String returnDate = format.format(date);
        return returnDate;
    }
}

Related

  1. getCurrentDateTimeISO8601()
  2. getCurrentDateTimeObj(String dateTime, String format)
  3. getCurrentDateTimeString()
  4. getCurrentDateTimeString(String returnFormat)
  5. getCurrentDateTimeStringValue()
  6. getCurrentDateWithDot()
  7. getCurrentDay()
  8. getCurrentDay()
  9. getCurrentDay()