Java Timestamp Convert To convertTimestampToString(Timestamp dateTime, String dateFormat)

Here you can find the source of convertTimestampToString(Timestamp dateTime, String dateFormat)

Description

convert timestamp to format yyyyMMdd

License

LGPL

Parameter

Parameter Description
dateTime a parameter

Return

String

Declaration

public static String convertTimestampToString(Timestamp dateTime, String dateFormat) 

Method Source Code


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

import java.sql.Timestamp;

public class Main {
    /**/* w  w  w.  ja va2 s.  c  om*/
     * convert timestamp to sql string date format
     * @param dateTime
     * @param withTime
     * @return String
     */
    public static String convertTimestampToString(Timestamp dateTime, boolean withTime) {
        String s = "";
        java.text.SimpleDateFormat ft = null;
        if (withTime) {
            ft = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        } else {
            ft = new java.text.SimpleDateFormat("yyyy-MM-dd");
        }
        s = ft.format(dateTime);
        return s;
    }

    /**
     * convert timestamp to format yyyyMMdd
     * @param dateTime
     * @return String
     */
    public static String convertTimestampToString(Timestamp dateTime, String dateFormat) {
        String s = "";
        java.text.SimpleDateFormat ft = null;
        ft = new java.text.SimpleDateFormat(dateFormat);
        s = ft.format(dateTime);
        return s;
    }
}

Related

  1. convertDate(Timestamp time)
  2. ConvertTimestamp(long sec)
  3. convertTimestamp(Timestamp timestamp)
  4. convertTimestampToDate(Timestamp timestamp)
  5. convertTimestampToDDMMMMYYYY(Timestamp dateTime)
  6. convertTimestampToString(Timestamp str)
  7. convertTimestampToStringWithoutTime(final Timestamp ts)
  8. convertToDate(Timestamp aTimeStamp)
  9. convertToDate(Timestamp timestamp)