Java Timestamp Format formatTimestamp(Timestamp timestamp, int iType)

Here you can find the source of formatTimestamp(Timestamp timestamp, int iType)

Description

format Timestamp

License

Open Source License

Declaration

public static String formatTimestamp(Timestamp timestamp, int iType) 

Method Source Code

//package com.java2s;
/**//from w ww  . j  a v  a 2  s. c  om
 * $RCSfile: DateUtil.java
 * $Revision: 1.0
 * $Date: Jan 30, 2011
 *
 * Copyright (C) 2010 SlFile, Inc. All rights reserved.
 *
 * This software is the proprietary information of SlFile, Inc.
 * Use is subject to license terms.
 */

import java.sql.Timestamp;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static String formatTimestamp(Timestamp timestamp, int iType) {
        String timeStr = "";
        if (timestamp != null) {
            timeStr = getStrDate(new Long(timestamp.getTime()), iType);
        }
        return timeStr;
    }

    public static String getStrDate(java.lang.Long lDate, int iType) {
        Date date = new Date(lDate.longValue());
        SimpleDateFormat simpleDateFormat = null;
        switch (iType) {
        case 0:
            simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            break;
        case 1:
            simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH");
            break;
        case 2:
            simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            break;
        case 3:
            simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            break;
        }

        String strDate = simpleDateFormat.format(date);
        return (strDate);
    }
}

Related

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