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


C# DateTime.AddHours方法代码示例

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


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

示例1: InstantToDateTime

            public static DateTime InstantToDateTime(double instant, DateTime start, TimeUnits units = TimeUnits.SECONDS)
            {
                DateTime instantAsDate = start;

                switch (units)
                {
                   case TimeUnits.YEARS:
                  instantAsDate = start.AddYears((int)instant);
                  break;
                   case TimeUnits.MONTHS:
                  instantAsDate = start.AddMonths((int)instant);
                  break;
                   case TimeUnits.DAYS:
                  instantAsDate = start.AddDays(instant);
                  break;
                   case TimeUnits.HOURS:
                  instantAsDate = start.AddHours(instant);
                  break;
                   case TimeUnits.MINUTES:
                  instantAsDate = start.AddMinutes(instant);
                  break;
                   case TimeUnits.SECONDS:
                  instantAsDate = start.AddSeconds(instant);
                  break;
                }

                return instantAsDate;
            }
开发者ID:JauchOnGitHub,项目名称:csharptoolbox,代码行数:28,代码来源:Conversions.cs

示例2: SspiSecurityToken

 public SspiSecurityToken(NetworkCredential networkCredential, bool extractGroupsForWindowsAccounts, bool allowUnauthenticatedCallers)
 {
     _networkCredential = SecurityUtils.GetNetworkCredentialsCopy(networkCredential);
     _extractGroupsForWindowsAccounts = extractGroupsForWindowsAccounts;
     _allowUnauthenticatedCallers = allowUnauthenticatedCallers;
     _effectiveTime = DateTime.UtcNow;
     _expirationTime = _effectiveTime.AddHours(10);
 }
开发者ID:smulholland2,项目名称:wcf,代码行数:8,代码来源:SspiSecurityToken.cs

示例3: CanAddHoursAcrossDstTransition_StartWithMismatchedKind

        public void CanAddHoursAcrossDstTransition_StartWithMismatchedKind()
        {
            var tz = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            var dt = new DateTime(2015, 3, 8, 9, 0, 0, DateTimeKind.Utc);
            var result = dt.AddHours(1, tz);

            var expected = new DateTimeOffset(2015, 3, 8, 3, 0, 0, TimeSpan.FromHours(-7));
            Assert.Equal(expected, result);
            Assert.Equal(expected.Offset, result.Offset);
        }
开发者ID:kronic,项目名称:corefxlab,代码行数:10,代码来源:DateTimeTests.cs

示例4: ParseHttpDate


//.........这里部分代码省略.........
            int year;
            int month;
            int day;
            int hour;
            int minute;
            int second;
            int millisecond;

            millisecond =  0;

            if (fIsANSIDateFormat) {
                day    = rgdwDateParseResults[DATE_ANSI_INDEX_DAY];
                month  = rgdwDateParseResults[DATE_ANSI_INDEX_MONTH];
                hour   = rgdwDateParseResults[DATE_ANSI_INDEX_HRS];
                minute = rgdwDateParseResults[DATE_ANSI_INDEX_MINS];
                second = rgdwDateParseResults[DATE_ANSI_INDEX_SECS];
                if (iLastLettered != DATE_ANSI_INDEX_YEAR) {
                    year   = rgdwDateParseResults[DATE_ANSI_INDEX_YEAR];
                }
                else {
                    // This is a fix to get around toString/toGMTstring (where the timezone is
                    // appended at the end. (See above)
                    year   = rgdwDateParseResults[DATE_INDEX_TZ];
                }
            }
            else {
                day    = rgdwDateParseResults[DATE_1123_INDEX_DAY];
                month  = rgdwDateParseResults[DATE_1123_INDEX_MONTH];
                year   = rgdwDateParseResults[DATE_1123_INDEX_YEAR];
                hour   = rgdwDateParseResults[DATE_1123_INDEX_HRS];
                minute = rgdwDateParseResults[DATE_1123_INDEX_MINS];
                second = rgdwDateParseResults[DATE_1123_INDEX_SECS];
            }

            //
            // Normalize the year, 90 == 1990, handle the year 2000, 02 == 2002
            //  This is Year 2000 handling folks!!!  We get this wrong and
            //  we all look bad.
            //

            if (year < 100) {
                year += ((year < 80) ? 2000 : 1900);
            }

            //
            // if we got misformed time, then plug in the current time
            // !lpszHrs || !lpszMins || !lpszSec
            //

            if ((i < 4)
                || (day > 31)
                || (hour > 23)
                || (minute > 59)
                || (second > 59)) {
                fRet = false;
                goto quit;
            }

            //
            // Now do the DateTime conversion
            //

            dtOut = new DateTime (year, month, day, hour, minute, second, millisecond);

            //
            // we want the system time to be accurate. This is _suhlow_
            // The time passed in is in the local time zone; we have to convert this into GMT.
            //

            if (iLastLettered==DATE_ANSI_INDEX_YEAR) {
                // this should be an unusual case.
                dtOut = dtOut.ToUniversalTime();
            }

            //
            // If we have an Offset to another Time Zone
            //   then convert to appropriate GMT time
            //

            if ((i > DATE_INDEX_TZ &&
                 rgdwDateParseResults[DATE_INDEX_TZ] != DATE_TOKEN_GMT)) {

                //
                // if we received +/-nnnn as offset (hhmm), modify the output FILETIME
                //

                double offset;

                offset = (double) rgdwDateParseResults[DATE_INDEX_TZ];
                dtOut.AddHours(offset);
            }

            // In the end, we leave it all in LocalTime

            dtOut = dtOut.ToLocalTime();

            quit:

            return fRet;
        }
开发者ID:uQr,项目名称:referencesource,代码行数:101,代码来源:_HTTPDateParse.cs


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