Skip to content

Instantly share code, notes, and snippets.

@tigawa
Created January 25, 2015 22:58
Show Gist options
  • Save tigawa/1ca3066a968600a84bfa to your computer and use it in GitHub Desktop.
Save tigawa/1ca3066a968600a84bfa to your computer and use it in GitHub Desktop.
public class DateUtils {
public static void main(String[] args) {
DateUtils dateUtils = new DateUtils();
// テストコード
int[] year_month_null = dateUtils.parseYearMonth(null);
if(year_month_null == null)
System.out.println("null ok");
int[] year_month_blank = dateUtils.parseYearMonth("");
if(year_month_blank == null)
System.out.println("blank ok");
int[] year_month = dateUtils.parseYearMonth("2015年1月¥t");
if(2015 == year_month[0])
System.out.println("year OK!!");
else
System.out.println("year NG!!");
if(1 == year_month[1])
System.out.println("month OK!!");
else
System.out.println("month NG!!");
}
// プロダクトコード
public int[] parseYearMonth(String str){
if(str == null || str.equals("")) return null;
int[] year_month = new int[]{0,0};
String[] y = str.split("月");
String[] x = y[0].split("年");
year_month[0] = Integer.parseInt(x[0]);
year_month[1] = Integer.parseInt(x[1]);
return year_month;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment