Java Timestamp to String timestampToString(java.sql.Timestamp a_Timestamp, String aS_Format)

Here you can find the source of timestampToString(java.sql.Timestamp a_Timestamp, String aS_Format)

Description

Converts java.sql.Timestamp to String with using specified format

License

Open Source License

Parameter

Parameter Description
a_Timestamp Timestamp containing time
aS_Format String containing format specifications if format is null then format is "yyyy-MM-dd hh:mm:ss"

Return

String containing datetime

Declaration


public static String timestampToString(java.sql.Timestamp a_Timestamp, String aS_Format) 

Method Source Code

//package com.java2s;
/*/*from   w ww  .java  2 s .c  o  m*/
NetForm Library
---------------
Copyright (C) 2001-2005 - Sampsa Sohlman, Teemu Sohlman
    
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
    
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.
    
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
*/

import java.text.SimpleDateFormat;

public class Main {
    /**
     * Converts java.sql.Timestamp to String with using specified format
     * @param a_Timestamp Timestamp containing time
     * @param aS_Format String containing format specifications
     * if format is null then format is "yyyy-MM-dd hh:mm:ss"
     * @return String containing datetime
     *
     * @see java.text.SimpleDateFormat for format options
     */

    public static String timestampToString(java.sql.Timestamp a_Timestamp, String aS_Format) {
        if (aS_Format == null) {
            aS_Format = "yyyy-MM-dd hh:mm:ss";
        }

        if (a_Timestamp == null)
            return "";

        SimpleDateFormat l_SimpleDateFormat = new SimpleDateFormat(aS_Format);

        return l_SimpleDateFormat.format(a_Timestamp);
    }
}

Related

  1. timestamp2Str(Timestamp time, String format)
  2. timestamp2String(final java.sql.Timestamp value)
  3. timestamp2String(Timestamp timestamp, String pattern)
  4. timestamptoStr(Timestamp time)
  5. timeStampToString(final Timestamp timestamp, final String format)
  6. timestampToString(long timestamp)
  7. timestampToString(long timestamp)
  8. timeStampToString(Timestamp date, String dateFmt)
  9. timestampToString(Timestamp now, String pattern)