当前位置: 首页>>代码示例>>C#>>正文


C# DateTime.CompareTo方法代码示例

本文整理汇总了C#中DateTime.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.CompareTo方法的具体用法?C# DateTime.CompareTo怎么用?C# DateTime.CompareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DateTime的用法示例。


在下文中一共展示了DateTime.CompareTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConvertGregorianToHijri

        /*========================ConvertGregorianToHijri============================
        ** Purpose: convert DateTime to Hdate(year,month,day)                                                   
        ** Arguments:                                                                                                                
        ** Input: DateTime                                                                                                         
        ** Output: Hijrah  date: year:yh, month:mh, day:dh                                                          
        ============================================================================*/
        private static void ConvertGregorianToHijri(DateTime time, ref int HijriYear, ref int HijriMonth, ref int HijriDay)
        {
            int index, b, DaysPerThisMonth;
            double nDays;
            TimeSpan ts;
            int yh1 = 0, mh1 = 0, dh1 = 0;

            Debug.Assert((time.Ticks >= minDate.Ticks) && (time.Ticks <= maxDate.Ticks), "Gregorian date is out of range.");

            // Find the index where we should start our search by quessing the Hijri year that we will be in HijriYearInfo.
            // A Hijri year is 354 or 355 days.  Use 355 days so that we will search from a lower index.

            index = (int)((time.Ticks - minDate.Ticks) / Calendar.TicksPerDay) / 355;
            do
            {
            } while (time.CompareTo(s_hijriYearInfo[++index].GregorianDate) > 0); //while greater

            if (time.CompareTo(s_hijriYearInfo[index].GregorianDate) != 0)
            {
                index--;
            }

            ts = time.Subtract(s_hijriYearInfo[index].GregorianDate);
            yh1 = index + MinCalendarYear;

            mh1 = 1;
            dh1 = 1;
            nDays = ts.TotalDays;
            b = s_hijriYearInfo[index].HijriMonthsLengthFlags;
            DaysPerThisMonth = 29 + (b & 1);

            while (nDays >= DaysPerThisMonth)
            {
                nDays -= DaysPerThisMonth;
                b = b >> 1;
                DaysPerThisMonth = 29 + (b & 1);
                mh1++;
            }
            dh1 += (int)nDays;

            HijriDay = dh1;
            HijriMonth = mh1;
            HijriYear = yh1;
        }
开发者ID:tijoytom,项目名称:corert,代码行数:50,代码来源:UmAlQuraCalendar.cs


注:本文中的DateTime.CompareTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。