public static long julianToPersian(long julianDate){
  long persianEpochInJulian=julianDate - persianToJulian(475L,0,1);
  long cyear=ceil(persianEpochInJulian,1029983D);
  long ycycle=cyear != 1029982L ? ((long)Math.floor((2816D * (double)cyear + 1031337D) / 1028522D)) : 2820L;
  long year=474L + 2820L * ((long)Math.floor(persianEpochInJulian / 1029983D)) + ycycle;
  long aux=(1L + julianDate) - persianToJulian(year,0,1);
  int month=(int)(aux > 186L ? Math.ceil((double)(aux - 6L) / 30D) - 1 : Math.ceil((double)aux / 31D) - 1);
  int day=(int)(julianDate - (persianToJulian(year,month,1) - 1L));
  return (year << 16) | (month << 8) | day;
}

public static long julianToPersian ( long julianDate ) { long persianEpochInJulian = julianDate - persianToJulian ( 475L , 0 , 1 ) ; long cyear = ceil ( persianEpochInJulian , 1029983D ) ; long ycycle = cyear != 1029982L ? ( ( long ) Math . floor ( ( 2816D * ( double ) cyear + 1031337D ) / 1028522D ) ) : 2820L ; long year = 474L + 2820L * ( ( long ) Math . floor ( persianEpochInJulian / 1029983D ) ) + ycycle ; long aux = ( 1L + julianDate ) - persianToJulian ( year , 0 , 1 ) ; int month = ( int ) ( aux > 186L ? Math . ceil ( ( double ) ( aux - 6L ) / 30D ) - 1 : Math . ceil ( ( double ) aux / 31D ) - 1 ) ; int day = ( int ) ( julianDate - ( persianToJulian ( year , month , 1 ) - 1L ) ) ; return ( year << 16 ) | ( month << 8 ) | day ; }
converts a provided julian day number ( i . e . the number of days since january 1 in the year 4713 bc ) to the persian ( shamsi ) date . since the persian calendar is a highly regular calendar , converting to and from a julian day number is not as difficult as it looks . basically it ' s a mather of dividing , rounding and multiplying .
