Java Today getToday(boolean ceOrTw, String deli)

Here you can find the source of getToday(boolean ceOrTw, String deli)

Description

get Today

License

Open Source License

Parameter

Parameter Description
deli : "/" => 2007/03/18

Return

Ex: true = 20070318 ; false = 0960318

Declaration

public static String getToday(boolean ceOrTw, String deli) 

Method Source Code

//package com.java2s;

import java.util.Calendar;

public class Main {
    /**/*from www .  ja v a 2  s.  c o m*/
     * @param deli
     *            : "/" => 2007/03/18
     * @return Ex: true = 20070318 ; false = 0960318
     */
    public static String getToday(boolean ceOrTw, String deli) {
        if (deli == null)
            deli = "";
        Calendar cal = Calendar.getInstance();
        int WTYear = (cal.get(Calendar.YEAR));
        String WTYearS = new String();
        if (ceOrTw) {
            WTYearS = fillZero(String.valueOf(WTYear), 4);
        } else {
            WTYearS = fillZero(String.valueOf(WTYear - 1911), 3);
        }
        int Month = cal.get(Calendar.MONTH) + 1;
        String MonthS = fillZero(String.valueOf(Month), 2);
        int DAY = cal.get(Calendar.DAY_OF_MONTH);
        String DAYS = fillZero(String.valueOf(DAY), 2);
        String WTDate = WTYearS + deli + MonthS + deli + DAYS;
        return WTDate;
    }

    private static String fillZero(String str, int len) {
        if (str == null)
            return "";
        len = len - str.length();
        if (len < 0)
            return str;
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < len; i++) {
            sb.append('0');
        }
        return sb.toString() + str;
    }
}

Related

  1. getToday()
  2. getToday()
  3. getToday()
  4. getToday()
  5. getToday()
  6. getToDay(boolean withTime)
  7. getToday(int hour, int minute, int second)
  8. getToday(String datePattern)
  9. getToday(String format)