Java Timestamp Format formatTimestamp(Timestamp t, int type)

Here you can find the source of formatTimestamp(Timestamp t, int type)

Description

ACME timestamp formatter

License

Open Source License

Parameter

Parameter Description
t jva.sql.Timestamp - if null uses current date

Return

formatted timestamp

Declaration

public static String formatTimestamp(Timestamp t, int type) 

Method Source Code

//package com.java2s;
/*/*from  ww w.  j a  va  2 s . co  m*/
The GUFF - The GNU Ultimate Framework Facility
Copyright (C) Simeosoft di Carlo Simeone
       
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.*;

import java.sql.Timestamp;

public class Main {
    public static final int FORMAT_YYYY_MM_DD_HH_MM_SS = 0;
    public static final int FORMAT_DD_MM_YYYY_HH_MM_SS = 1;
    public static final int FORMAT_DD_MM_YYYY_SLASH = 2;

    /**
     * ACME timestamp formatter
     * @param t  jva.sql.Timestamp - if null uses current date
     * @return formatted timestamp
     */
    public static String formatTimestamp(Timestamp t, int type) {
        DateFormat format = null;
        switch (type) {
        case FORMAT_DD_MM_YYYY_HH_MM_SS:
            format = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            break;
        case FORMAT_YYYY_MM_DD_HH_MM_SS:
            format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            break;
        case FORMAT_DD_MM_YYYY_SLASH:
            format = new SimpleDateFormat("dd/MM/yyyy");
            break;
        }
        if (t == null) {
            t = new Timestamp(System.currentTimeMillis());
        }
        return format.format(t);
    }
}

Related

  1. formatTimestamp(long timestamp)
  2. formatTimestamp(long ts)
  3. formatTimestamp(String dateStr, String granularity)
  4. formatTimestamp(Timestamp dataHora)
  5. formatTimeStamp(Timestamp t)
  6. formatTimestamp(Timestamp timestamp)
  7. formatTimestamp(Timestamp timestamp, int iType)
  8. formatTimestamp(Timestamp timestamp, String pattern)
  9. formatTimestamp(Timestamp ts, int dateStyle, int timeStyle, Locale locale)