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

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

Description

set Calendar

License

Apache License

Declaration

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

Method Source Code

//package com.java2s;
/* ====================================================================
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.//from  w w w .j  a v  a  2  s. c  om
 ==================================================================== */

import java.util.Calendar;

import java.util.GregorianCalendar;

public class Main {
    public static void setCalendar(Calendar calendar, int wholeDays,
            int millisecondsInDay, boolean use1904windowing) {
        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(GregorianCalendar.MILLISECOND, millisecondsInDay);
    }
}

Related

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