Here you can find the source of getCalendar(String dateStr, int inputYearType, int outputYearType)
Parameter | Description |
---|
public static Calendar getCalendar(String dateStr, int inputYearType, int outputYearType)
//package com.java2s; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.StringTokenizer; import java.util.Vector; public class Main { final public static int EN = 1; final public static int TH = 2; /**// w w w . j a v a2 s . c o m * @param String("dd/MM/yyyy) * @return Calendar */ public static Calendar getCalendar(String dateStr, int inputYearType, int outputYearType) { // date (dd/MM/yyyy) Vector d = getElementDate(dateStr); int day = Integer.parseInt((String) d.elementAt(0)); int month = Integer.parseInt((String) d.elementAt(1)); int year = Integer.parseInt((String) d.elementAt(2)); switch (inputYearType) { case EN: if (outputYearType == TH) year += 543; break; case TH: if (outputYearType == EN) year -= 543; break; } return new GregorianCalendar(year, month - 1, day); //MUST SUB 1, BECAUSE MONTH START FROM 0 } /** * @param String("dd/MM/yyyy) * @return int */ public static Vector getElementDate(String dateStr) { Vector vec = new Vector(); StringTokenizer stk = new StringTokenizer(dateStr, "/"); while (stk.hasMoreElements()) vec.addElement((String) stk.nextElement()); return vec; } }