Here you can find the source of formatTimestamp(Timestamp t, int type)
Parameter | Description |
---|---|
t | jva.sql.Timestamp - if null uses current date |
public static String formatTimestamp(Timestamp t, int type)
//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); } }