Java Timestamp Field getDateString(java.sql.Timestamp ts)

Here you can find the source of getDateString(java.sql.Timestamp ts)

Description

get Date String

License

Open Source License

Declaration

public static String getDateString(java.sql.Timestamp ts) 

Method Source Code

//package com.java2s;

public class Main {
    public static String getDateString(java.sql.Timestamp ts) {
        if (ts == null) {
            return "";
        }//from   w  ww  . ja v a  2 s  .com
        return Timestamp2DDMMYYYY(ts);
    }

    public static String Timestamp2DDMMYYYY(java.sql.Timestamp ts) {
        if (ts == null) {
            return "";
        } else {
            java.util.Calendar calendar = java.util.Calendar.getInstance();
            calendar.setTime(new java.util.Date(ts.getTime()));

            String strTemp = Integer.toString(calendar.get(calendar.DAY_OF_MONTH));
            if (calendar.get(calendar.DAY_OF_MONTH) < 10) {
                strTemp = "0" + strTemp;
            }
            if (calendar.get(calendar.MONTH) + 1 < 10) {
                return strTemp + "/0" + (calendar.get(calendar.MONTH) + 1) + "/" + calendar.get(calendar.YEAR);
            } else {
                return strTemp + "/" + (calendar.get(calendar.MONTH) + 1) + "/" + calendar.get(calendar.YEAR);
            }
        }
    }
}

Related

  1. getDateString(Timestamp time, String pattern)
  2. getDateTime(Timestamp argRenDt)
  3. getDateTime(Timestamp timestamp)
  4. getDateTimeFromSqlTimestamp(Timestamp timestamp)