Java Date Format convertDateToString(Date date)

Here you can find the source of convertDateToString(Date date)

Description

Converts the given date to the specified string pattern "yyyy-MM-dd HH:mm:ss";

License

Open Source License

Parameter

Parameter Description
date a parameter

Declaration

public static String convertDateToString(Date date) 

Method Source Code

//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

import java.text.FieldPosition;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final String TALEND_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss";

    /**//from w w w. j av  a 2s . c o  m
     * Converts the given date to the specified string pattern "yyyy-MM-dd HH:mm:ss";
     * 
     * @param date
     * @return
     */
    public static String convertDateToString(Date date) {
        String result = convertDateToString(date, TALEND_DATE_PATTERN);
        return result;
    }

    public static String convertDateToString(Date date, String pattern) {
        StringBuffer result = new StringBuffer();

        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        sdf.format(date, result, new FieldPosition(0));
        return result.toString();
    }
}

Related

  1. convertDateToISO8601(Date date)
  2. convertDateToMMDDYYYY(Date date)
  3. convertDateToRpcFormat(Date date)
  4. convertDateToString(Date aDate)
  5. convertDateToString(Date aDate)
  6. convertDateToString(Date date)
  7. convertDateToString(Date date)
  8. convertDateToString(Date date)
  9. convertDateToString(Date date)