Java Timestamp Format Timestamp2HHMMSS(java.sql.Timestamp ts, int iStyle)

Here you can find the source of Timestamp2HHMMSS(java.sql.Timestamp ts, int iStyle)

Description

Timestamp HHMMSS

License

Open Source License

Declaration

public static String Timestamp2HHMMSS(java.sql.Timestamp ts, int iStyle) 

Method Source Code

//package com.java2s;

public class Main {
    public static String Timestamp2HHMMSS(java.sql.Timestamp ts, int iStyle) {
        if (ts == null) {
            return "";
        }//  ww w .  ja va  2  s.c o  m
        java.util.Calendar calendar = java.util.Calendar.getInstance();
        calendar.setTime(new java.util.Date(ts.getTime()));

        String strTemp;
        if (iStyle == 0) {
            strTemp = Integer.toString(calendar.get(calendar.HOUR_OF_DAY));
        } else {
            strTemp = Integer.toString(calendar.get(calendar.HOUR_OF_DAY));
        }

        if (strTemp.length() < 2) {
            strTemp = "0" + strTemp;
        }
        if (calendar.get(calendar.MINUTE) < 10) {
            strTemp += ":0" + calendar.get(calendar.MINUTE);
        } else {
            strTemp += ":" + calendar.get(calendar.MINUTE);
        }
        if (calendar.get(calendar.SECOND) < 10) {
            strTemp += ":0" + calendar.get(calendar.SECOND);
        } else {
            strTemp += ":" + calendar.get(calendar.SECOND);
        }

        if (iStyle != 0) {
            if (calendar.get(calendar.AM_PM) == calendar.AM) {
                strTemp += " AM";
            } else {
                strTemp += " PM";
            }
        }
        return strTemp;
    }
}

Related

  1. sortedTimestampFormat(Date date)
  2. stringConvertToTimestamp(String value, String format)
  3. TimeStamp2Date(long timestampString, String formats)
  4. timeStamp2Date(String seconds, String format)
  5. Timestamp2DDMMYYYY(java.sql.Timestamp ts)
  6. timestamp2String(long source, DateFormat format)
  7. Timestamp2UTC(Timestamp mytime)
  8. timestampConvertToString(int timeStamp, String format)
  9. timeStampForFileName(final String simpleDateFormat)