Given a Calendar, return the number of days since 18991231. - CSharp System

CSharp examples for System:DateTime Day

Description

Given a Calendar, return the number of days since 18991231.

Demo Code

/* ====================================================================
   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./*  ww w  .  j av  a2  s  . c o  m*/
==================================================================== */
using System.Text;
using System.Text.RegularExpressions;
using System;
using System.Globalization;

public class Main{
        /// <summary>
        /// Given a Calendar, return the number of days since 1899/12/31.
        /// </summary>
        /// <param name="cal">the date</param>
        /// <param name="use1904windowing">if set to <c>true</c> [use1904windowing].</param>
        /// <returns>number of days since 1899/12/31</returns>
        public static int AbsoluteDay(DateTime cal, bool use1904windowing)
        {
            int daynum = (cal - new DateTime(1899, 12, 31)).Days;
            if (cal > new DateTime(1900, 3, 1) && use1904windowing)
            {
                daynum++;
            }
            return daynum;
        }
}

Related Tutorials