package com.rule.xxx;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/*
author - dr vijay
*/
public class FinancialYear
{
/**
* Gets the financial year.
*
* @param d the d
* @return the financial year
*/
public static int getFinancialYear ( Date d )
{
int month;
int year;
Calendar cal = Calendar.getInstance ();
cal.setTime ( d );
//calendar will start from 0-11 [0=jan, 11=dec]
month = cal.get ( Calendar.MONTH );
int advance = ( month < 3 ) ? 0 : 1;
year = cal.get ( Calendar.YEAR ) + advance;
return year;
}
public static void main ( String [] args ) throws Exception
{
String sDate1 = "01/04/2019";
Date date1 = new SimpleDateFormat ( "dd/MM/yyyy" ).parse ( sDate1 );
System.out.println ( sDate1 + " \t " + date1 );
System.out.println ( FinancialYear.getFinancialYear ( date1 ) );
}
}
OUTPUT
01/04/2018 Sun Apr 01 00:00:00 IST 2018
2019
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/*
author - dr vijay
*/
public class FinancialYear
{
/**
* Gets the financial year.
*
* @param d the d
* @return the financial year
*/
public static int getFinancialYear ( Date d )
{
int month;
int year;
Calendar cal = Calendar.getInstance ();
cal.setTime ( d );
//calendar will start from 0-11 [0=jan, 11=dec]
month = cal.get ( Calendar.MONTH );
int advance = ( month < 3 ) ? 0 : 1;
year = cal.get ( Calendar.YEAR ) + advance;
return year;
}
public static void main ( String [] args ) throws Exception
{
String sDate1 = "01/04/2019";
Date date1 = new SimpleDateFormat ( "dd/MM/yyyy" ).parse ( sDate1 );
System.out.println ( sDate1 + " \t " + date1 );
System.out.println ( FinancialYear.getFinancialYear ( date1 ) );
}
}
OUTPUT
01/04/2018 Sun Apr 01 00:00:00 IST 2018
2019
No comments:
Post a Comment