Java Timestamp dateTimeToString(Timestamp dt, String df)

Here you can find the source of dateTimeToString(Timestamp dt, String df)

Description

DateTime convert to String.

License

Apache License

Return

String representation of the given DateTime and DateFormat.

Declaration

public static String dateTimeToString(Timestamp dt, String df) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.sql.Timestamp;

import java.text.SimpleDateFormat;

public class Main {
    /**/*from ww  w  .j  ava  2  s .  com*/
     * DateTime convert to String.
     * 
     * @return String representation of the given DateTime and DateFormat.
     */
    public static String dateTimeToString(Timestamp dt, String df) {
        String pstrDate = null; // return value
        if (dt == null) {
            return "";
        }
        String formatStyle = null;
        if ((df == null) || (df.equals(""))) {
            formatStyle = "yyyy-MM-dd HH:mm:ss";
        } else {
            formatStyle = df;
        }
        SimpleDateFormat oFormatter = null;
        try {
            oFormatter = new SimpleDateFormat(formatStyle);
            pstrDate = oFormatter.format(formatStyle);
        } catch (Exception e) {
            oFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            pstrDate = oFormatter.format(dt);
        }
        return pstrDate;
    }
}

Related

  1. dateAndTimeToTimestamp(Date data, Time hora)
  2. dateIntToTimestamp(int dateInt)
  3. datesDiffer(Timestamp a, Timestamp b)
  4. dateStringToTimestamp(String dateStr)
  5. datetime2ToTimestamp(long value, int fraction, int width)
  6. dateToOracleStr(java.sql.Timestamp ts)
  7. dayNumber(Timestamp stamp)
  8. daysBetween(Timestamp t1, Timestamp t2)
  9. delta_hours(Timestamp startdate, Timestamp enddate)