Java Timestamp timestampPlusDay2DDMMYYYY(java.sql.Timestamp ts, int iDayPlus)

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

Description

return string dd/mm/yyyy from a Timestamp + a addtional day

License

Open Source License

Parameter

Parameter Description
ts a parameter
iDayPlus number of day to add

Declaration

public static String timestampPlusDay2DDMMYYYY(java.sql.Timestamp ts, int iDayPlus) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from w ww  .  j  a  va  2  s  . co m
     *   return string dd/mm/yyyy from a Timestamp + a addtional day
     * @param ts
     * @param iDayPlus    number of day to add
     * @return
     */
    public static String timestampPlusDay2DDMMYYYY(java.sql.Timestamp ts, int iDayPlus) {
        if (ts == null) {
            return "";
        }
        java.util.Calendar calendar = java.util.Calendar.getInstance();
        calendar.setTime(new java.util.Date(ts.getTime()));
        int iDay = calendar.get(calendar.DAY_OF_MONTH);
        calendar.set(calendar.DAY_OF_MONTH, iDay + iDayPlus);

        java.sql.Timestamp tsNew = new java.sql.Timestamp((calendar.getTime()).getTime());
        return Timestamp2DDMMYYYY(tsNew);
    }

    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. TimeStampMonthDayYear(Timestamp timestamp)
  2. timestampNow()
  3. TimestampNow()
  4. timestampOf(final ZonedDateTime time)
  5. timestampPlusDay(java.sql.Timestamp ts, int iDayPlus)
  6. trunc(Timestamp dayTime, String trunc)
  7. truncateFractionalSeconds(Timestamp timestamp)
  8. truncateTimestamp(Timestamp timestamp, String period)
  9. truncNanos(Timestamp timestamp)