อันนี้ไม่มีอะไรครับ ผมแค่เขียนไว้กันลืมเฉยๆ โดยใส่ date เข้าไป
เช่นปีนี้คือ 2556 ถ้า date คือ 22-01-2556 มันก็จะคืนค่าปีงบประมาณเป็น 2556 แต่ถ้า date เป็น 05-10-2556 มันก็จะคืนค่าปีงบประมาณเป็น 2557 ครับ
package com.blogspot.na5cent.utils;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
/**
*
* @author Redcrow
*/
public class DateUtils {
private static final Locale THAI_LOCALE = new Locale("th", "TH");
/**
* fiscal year of thailand is begin 1 october in that year and end 30
* september of next year
*
* @param date
* @return fiscal year
*/
public static int getFiscalYear(Date date) {
Calendar calendar = Calendar.getInstance(THAI_LOCALE);
calendar.setTime(date);
int month = calendar.get(Calendar.MONTH) + 1;
int year = calendar.get(Calendar.YEAR);
if (month > 9) {
year = year + 1;
}
return year;
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น