As a beginner in java, I am trying some simple case. As from this SO post and 2nd link to the pdf file given there, I have developed this code:
import java.time.LocalTime;
import java.util.Calendar;
import static java.lang.Math.acos;
import static java.lang.Math.cos;
import static java.lang.Math.sin;
import static java.lang.Math.tan;
/**
 * Created by rudra on 17/02/18.
 */
public class PathOfSun {
    static public double getTime() {
        LocalTime loacltime = LocalTime.now();//.getHour();
        int tzone = 5; //TODO: placeholder, will be calculated
        //    int localhour = time.getHour();
        int hour = loacltime.getHour();
        int min = loacltime.getMinute();
        int sec = loacltime.getSecond();
        double lat  =  latlang.Lat;
        double lang = latlang.Lang;
        Calendar calendar = Calendar.getInstance();
        int dayofyear = calendar.get(Calendar.DAY_OF_YEAR);
        int daysthisyear = calendar.getActualMaximum(Calendar.DAY_OF_YEAR);
        double pi = Math.PI;
        double gamma = (2 * pi / daysthisyear) * (dayofyear - 1 + (hour - 12) / 24);
        double eqtime = 229.18 * (0.000075 + 0.001868 * cos(gamma) - 0.032077 * sin(gamma) -
                0.014615 * cos(2 * gamma) - 0.04849 * sin(2 * gamma));
        double decl = 0.006918 - 0.399912 * cos(gamma) + 0.070257 * sin(gamma) - 0.006758 * cos(2 * gamma)
                + 0.000907 * sin(2 * gamma) - 0.002697 * cos(3 * gamma) + 0.00148 * sin(3 * gamma);
        double toffset = eqtime + 4 * lang + 60 * tzone;
        double tst = 60 * hour + min + sec / 60 + toffset;
        double ha = tst / 4 - 180;
        // Zenith
        double phi = acos(sin(lat) * sin(decl) + cos(lat) * cos(decl) * cos(ha));
        // Azimuth
        double theta = 180 - acos((sin(lat) * cos(phi) - sin(decl)) / (cos(lat) * sin(phi)));
        // Calculating the hourAngle as in second page
        // At sunrise
        double ha2 = acos(cos(90.8*180/pi)/cos(lat)*cos(decl)-tan(lat)*tan(decl));
        double stime = 720 - 4 * (lang - ha2) - eqtime;
        System.out.println("Time of Sun "+ stime);
        return stime;
    }
which, when called as:
    PathOfSun.getTime();
is giving wrong time, means, the stime for sunset and sunrise (+/- ha2) is giving almost same value.
Is there any mistake in my code? Please kindly help me doing this correct.