Here you can find the source of getToday(boolean ceOrTw, String deli)
Parameter | Description |
---|---|
deli | : "/" => 2007/03/18 |
public static String getToday(boolean ceOrTw, String deli)
//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; } }