Java Calendar Millisecond setCalendar(Calendar calendar, int wholeDays, int millisecondsInDay, boolean use1904windowing, boolean roundSeconds)

Here you can find the source of setCalendar(Calendar calendar, int wholeDays, int millisecondsInDay, boolean use1904windowing, boolean roundSeconds)

Description

set Calendar

License

Apache License

Declaration

public static void setCalendar(Calendar calendar, int wholeDays, int millisecondsInDay,
            boolean use1904windowing, boolean roundSeconds) 

Method Source Code


//package com.java2s;
/* NOTICE: This file has been changed by Plutext Pty Ltd for use in docx4j.
 * The package name has been changed; there may also be other changes.
 * // w  ww.  ja  v a 2s.c om
 * This notice is included to meet the condition in clause 4(b) of the License. 
 */

import java.util.Calendar;

public class Main {
    public static void setCalendar(Calendar calendar, int wholeDays, int millisecondsInDay,
            boolean use1904windowing, boolean roundSeconds) {
        int startYear = 1900;
        int dayAdjust = -1; // Excel thinks 2/29/1900 is a valid date, which it isn't
        if (use1904windowing) {
            startYear = 1904;
            dayAdjust = 1; // 1904 date windowing uses 1/2/1904 as the first day
        } else if (wholeDays < 61) {
            // Date is prior to 3/1/1900, so adjust because Excel thinks 2/29/1900 exists
            // If Excel date == 2/29/1900, will become 3/1/1900 in Java representation
            dayAdjust = 0;
        }
        calendar.set(startYear, 0, wholeDays + dayAdjust, 0, 0, 0);
        calendar.set(Calendar.MILLISECOND, millisecondsInDay);
        if (calendar.get(Calendar.MILLISECOND) == 0) {
            calendar.clear(Calendar.MILLISECOND);
        }
        if (roundSeconds) {
            calendar.add(Calendar.MILLISECOND, 500);
            calendar.clear(Calendar.MILLISECOND);
        }
    }
}

Related

  1. getMillisecond(Calendar calendar)
  2. getMilliSinceMidnight(Calendar arg)
  3. hasZeroMilliSeconds(Calendar cal)
  4. newCalendar(long timeInMillis)
  5. setCalendar(Calendar calendar, int wholeDays, int millisecondsInDay, boolean use1904windowing)
  6. setCalendarTime(Calendar inCalendar, int hr, int min, int sec, int milliSec)
  7. setTimeInMillis(Calendar _calendar, long _timemillis)
  8. toCalendar(final long millis)
  9. toCalendar(long millis)