Code example for Calendar

Methods: clearclonegetFirstDayOfWeekgetTimeset

0
     * 
     * @throws NullPointerException if <code>calendar</code> is 
     *     <code>null</code>. 
     */ 
    public long getFirstMillisecond(Calendar calendar) {
        Calendar c = (Calendar) calendar.clone();
        c.clear();
        c.set(Calendar.YEAR, this.year);
        c.set(Calendar.WEEK_OF_YEAR, this.week);
        c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
        c.set(Calendar.HOUR, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        //return c.getTimeInMillis();  // this won't work for JDK 1.3 
        return c.getTime().getTime();
    } 
 
    /** 
     * Returns the last millisecond of the week, evaluated using the supplied 
     * calendar (which determines the time zone). 
     * 
     * @param calendar  the calendar (<code>null</code> not permitted). 
     * 
     * @return The last millisecond of the week. 
     * 
     * @throws NullPointerException if <code>calendar</code> is 
     *     <code>null</code>. 
     */ 
    public long getLastMillisecond(Calendar calendar) {
        Calendar c = (Calendar) calendar.clone();
        c.clear();
        c.set(Calendar.YEAR, this.year);
        c.set(Calendar.WEEK_OF_YEAR, this.week + 1);
        c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
        c.set(Calendar.HOUR, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        //return c.getTimeInMillis();  // this won't work for JDK 1.3 
        return c.getTime().getTime() - 1;
    } 
 
    /** 
     * Returns a string representing the week (e.g. "Week 9, 2002"). 
     *