Code example for Calendar

Methods: get, getTime, getTimeZone

0
    } 
 
    private static double adjustForDST(double localMeanTime, Calendar date)
    { 
        double localTime = localMeanTime;
        if (date.getTimeZone().inDaylightTime(date.getTime()))
        { 
            localTime++;
        } 
        if (localTime > 24.0)
        { 
            localTime -= 24;
        } 
        return localTime;
    } 
 
    /** 
     * Returns the local rise/set time in the HH:MM form. 
     *  
     * @param localTime <code>double</code> representation of the local rise/set time. 
     * @return <code>String</code> representation of the local rise/set time in HH:MM format. 
     */ 
    public static String getLocalTimeAsString(double localTime)
    { 
        int hour = (int) Math.floor(localTime);
        int minutes = (int) Math.round((localTime - hour) * 60);
 
        if (minutes == 60)
        { 
            minutes = 0;
            hour++;
        } 
 
        String minuteString = minutes < 10 ? "0" + String.valueOf(minutes) : String.valueOf(minutes);
        String hourString = (hour < 10) ? "0" + String.valueOf(hour) : String.valueOf(hour);
        return hourString + ":" + minuteString;
    } 
 
    private static int getDayOfYear(Calendar date)
    { 
        return date.get(Calendar.DAY_OF_YEAR);
    } 
 
    private static double getUTCOffSet(Calendar date)
    { 
        return date.get(Calendar.ZONE_OFFSET) / 3600000;
    } 
 
}