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


C# DateTime.Add方法代码示例

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


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

示例1: FrequencyParameter_NoArgPassed_ThruDate

 public void FrequencyParameter_NoArgPassed_ThruDate()
 {
     FrequencyParameter testParameter = new FrequencyParameter();
     DateTime expectedResult = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
     expectedResult = expectedResult.Add(new TimeSpan(1, 0, 0, 0));
     Assert.AreEqual(expectedResult, testParameter.ThruDate);
 }
开发者ID:aaronmcooke,项目名称:Mono-Framework,代码行数:7,代码来源:FrequencyParameter_UnitTests.cs

示例2: FrequencyParameter_NoArgPassed_ReportingPeriod

 public void FrequencyParameter_NoArgPassed_ReportingPeriod()
 {
     FrequencyParameter testParameter = new FrequencyParameter();
     DateTime fromResult = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
     DateTime thruResult = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
     thruResult = thruResult.Add(new TimeSpan(1, 0, 0, 0));
     TimeSpan expectedResult = thruResult.Subtract(fromResult);
     Assert.AreEqual(expectedResult, testParameter.ReportingPeriod);
 }
开发者ID:aaronmcooke,项目名称:Mono-Framework,代码行数:9,代码来源:FrequencyParameter_UnitTests.cs

示例3: RolePrincipal

		public RolePrincipal (IIdentity identity)
		{
			if (identity == null)
				throw new ArgumentNullException ("identity");
			
			this._identity = identity;
			this._cookiePath = RoleManagerConfig.CookiePath;
			this._issueDate = DateTime.Now;
			this._expireDate = _issueDate.Add (RoleManagerConfig.CookieTimeout);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:10,代码来源:RolePrincipal.cs

示例4: Default

        public static DateTimeOffset Default(DateTime dt, TimeZoneInfo timeZone)
        {
            if (dt.Kind != DateTimeKind.Unspecified)
            {
                var dto = new DateTimeOffset(dt);
                return TimeZoneInfo.ConvertTime(dto, timeZone);
            }

            if (timeZone.IsAmbiguousTime(dt))
            {
                var earlierOffset = timeZone.GetUtcOffset(dt.AddDays(-1));
                return new DateTimeOffset(dt, earlierOffset);
            }

            if (timeZone.IsInvalidTime(dt))
            {
                var earlierOffset = timeZone.GetUtcOffset(dt.AddDays(-1));
                var laterOffset = timeZone.GetUtcOffset(dt.AddDays(1));
                var transitionGap = laterOffset - earlierOffset;
                return new DateTimeOffset(dt.Add(transitionGap), laterOffset);
            }

            return new DateTimeOffset(dt, timeZone.GetUtcOffset(dt));
        }
开发者ID:kronic,项目名称:corefxlab,代码行数:24,代码来源:TimeZoneOffsetResolvers.cs

示例5: OnIncrement

        /// <summary>
        /// Performs addition of a date time and a time span in a global context.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="timeSpan">The time span.</param>
        /// <returns>The DateTime after incrementing by TimeSpan.</returns>
        public virtual DateTime OnIncrement(DateTime value, TimeSpan timeSpan)
        {
            // special case: value is at DateTime.MaxValue
            if (DateTime.MaxValue.Date == value.Date && value.TimeOfDay.Add(timeSpan) > TimeSpan.FromDays(1))
            {
                return value.AddDays(-1).Add(timeSpan);
            }

            return value.Add(timeSpan);
        }
开发者ID:modulexcite,项目名称:SilverlightToolkit,代码行数:16,代码来源:TimeGlobalizationInfo.cs

示例6: DecryptTicket

		void DecryptTicket (string encryptedTicket)
		{
			if (encryptedTicket == null || encryptedTicket == String.Empty)
				throw new ArgumentException ("Invalid encrypted ticket", "encryptedTicket");

			byte [] ticketBytes = GetBytesFromBase64 (encryptedTicket);
			byte [] decryptedTicketBytes = null;

			CookieProtection cookieProtection = RoleManagerConfig.CookieProtection;

			if (cookieProtection == CookieProtection.All) {
				decryptedTicketBytes = MachineKeySectionUtils.VerifyDecrypt (MachineConfig, ticketBytes);
			} else if (cookieProtection == CookieProtection.Encryption) {
				decryptedTicketBytes = MachineKeySectionUtils.Decrypt (MachineConfig, ticketBytes);
			} else if (cookieProtection == CookieProtection.Validation) {
				decryptedTicketBytes = MachineKeySectionUtils.Verify (MachineConfig, ticketBytes);
			}

			if (decryptedTicketBytes == null)
				throw new HttpException ("ticket validation failed");

			MemoryStream ticket = new MemoryStream (decryptedTicketBytes);
			BinaryReader reader = new BinaryReader (ticket);

			// version
			_version = reader.ReadInt32 ();

			// issued date
			_issueDate = new DateTime (reader.ReadInt64 ());

			// expire date
			_expireDate = new DateTime (reader.ReadInt64 ());

			// cookie path
			_cookiePath = reader.ReadString ();
			
			// roles
			string roles = reader.ReadString ();

			if (!Expired) {
				InitializeRoles (roles);
				//update ticket if less than half of CookieTimeout remaining.
				if (Roles.CookieSlidingExpiration){
					if (_expireDate-DateTime.Now < TimeSpan.FromTicks (RoleManagerConfig.CookieTimeout.Ticks/2))	{
						_issueDate = DateTime.Now;
						_expireDate = DateTime.Now.Add (RoleManagerConfig.CookieTimeout);
						SetDirty ();
					}
				}
			} else {
				// issue a new ticket
				_issueDate = DateTime.Now;
				_expireDate = _issueDate.Add (RoleManagerConfig.CookieTimeout);
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:55,代码来源:RolePrincipal.cs

示例7: DecryptTicket

		void DecryptTicket (string encryptedTicket)
		{
			if (encryptedTicket == null || encryptedTicket == String.Empty)
				throw new ArgumentException ("Invalid encrypted ticket", "encryptedTicket");

			byte [] ticketBytes = GetBytesFromBase64 (encryptedTicket);
			byte [] decryptedTicketBytes = null;

			CookieProtection cookieProtection = RoleManagerConfig.CookieProtection;
			if (cookieProtection == CookieProtection.All || cookieProtection == CookieProtection.Encryption) {
				ICryptoTransform decryptor;
				decryptor = TripleDES.Create ().CreateDecryptor (
					MachineKeySectionUtils.DecryptionKey192Bits (MachineConfig),
					InitVector);
				decryptedTicketBytes = decryptor.TransformFinalBlock (ticketBytes, 0, ticketBytes.Length);
			}
			else
				decryptedTicketBytes = ticketBytes;

			if (cookieProtection == CookieProtection.All || cookieProtection == CookieProtection.Validation) {
				byte [] validationBytes = MachineKeySectionUtils.ValidationKeyBytes (MachineConfig);
				byte [] rolesWithValidationBytes = null;
				byte [] tmpValidation = null;

				int hashSize = (MachineConfig.Validation == MachineKeyValidation.MD5) ? 16 : 20; //md5 is 16 bytes, sha1 is 20 bytes

				rolesWithValidationBytes = new byte [decryptedTicketBytes.Length - hashSize + validationBytes.Length];

				Buffer.BlockCopy (decryptedTicketBytes, 0, rolesWithValidationBytes, 0, decryptedTicketBytes.Length - hashSize);
				Buffer.BlockCopy (validationBytes, 0, rolesWithValidationBytes, decryptedTicketBytes.Length - hashSize, validationBytes.Length);

				switch (MachineConfig.Validation) {
					case MachineKeyValidation.MD5:
						tmpValidation = MD5.Create ().ComputeHash (rolesWithValidationBytes);
						break;

					case MachineKeyValidation.TripleDES:
					case MachineKeyValidation.SHA1:
						tmpValidation = SHA1.Create ().ComputeHash (rolesWithValidationBytes);
						break;
				}
				for (int i = 0; i < tmpValidation.Length; i++) {
					if (i >= decryptedTicketBytes.Length ||
						tmpValidation [i] != decryptedTicketBytes [i + decryptedTicketBytes.Length - hashSize])
						throw new HttpException ("ticket validation failed");
				}
			}

			MemoryStream ticket = new MemoryStream (decryptedTicketBytes);
			BinaryReader reader = new BinaryReader (ticket);

			// version
			_version = reader.ReadInt32 ();

			// issued date
			_issueDate = new DateTime (reader.ReadInt64 ());

			// expire date
			_expireDate = new DateTime (reader.ReadInt64 ());

			// cookie path
			_cookiePath = reader.ReadString ();
			
			// roles
			string roles = reader.ReadString ();

			if (!Expired) {
				InitializeRoles (roles);
				//update ticket if less than half of CookieTimeout remaining.
				if (Roles.CookieSlidingExpiration){
					if (_expireDate-DateTime.Now < TimeSpan.FromTicks (RoleManagerConfig.CookieTimeout.Ticks/2))	{
						_issueDate = DateTime.Now;
						_expireDate = DateTime.Now.Add (RoleManagerConfig.CookieTimeout);
						SetDirty ();
					}
				}
			} else {
				// issue a new ticket
				_issueDate = DateTime.Now;
				_expireDate = _issueDate.Add (RoleManagerConfig.CookieTimeout);
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:82,代码来源:RolePrincipal.cs

示例8: FrequencyParameter_NullPassed

            public void FrequencyParameter_NullPassed()
            {
                DateTime testFrom = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
                DateTime testThru = testFrom.Add(new TimeSpan(1, 0, 0, 0));

                FrequencyParameter testParameter = new FrequencyParameter(null);

                Assert.Greater(testParameter.Errors.Count, 0);
                Assert.AreEqual(testFrom, testParameter.FromDate);
                Assert.AreEqual(testThru, testParameter.ThruDate);
            }
开发者ID:aaronmcooke,项目名称:Mono-Framework,代码行数:11,代码来源:FrequencyParameter_UnitTests.cs


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