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


C# this.AddHours方法代码示例

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


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

示例1: AM

 public static DateTime AM(this DateTime d)
 {
     Reject24HourTime(d);
     if (d.Hour < 12)
         return d;
     return d.AddHours(-12);
 }
开发者ID:janovesk,项目名称:FluentTime,代码行数:7,代码来源:DateTimeCreation.cs

示例2: Interval

 public static DateTime Interval(this DateTime date, DateTimePart? intervalType, int? intervalVal)
 {
     if (intervalType.HasValue && intervalVal.HasValue)
     {
         switch (intervalType.Value)
         {
             case DateTimePart.Year:
                 return date.AddYears(intervalVal.Value);
             case DateTimePart.Month:
                 return date.AddMonths(intervalVal.Value);
             case DateTimePart.Day:
                 return date.AddDays((double)intervalVal.Value);
             case DateTimePart.Hour:
                 return date.AddHours((double)intervalVal.Value);
             case DateTimePart.Munite:
                 return date.AddMinutes((double)intervalVal.Value);
             case DateTimePart.Second:
                 return date.AddSeconds((double)intervalVal.Value);
             case DateTimePart.Week:
                 return date.AddDays((double)intervalVal.Value * 7);
             case DateTimePart.Quarter:
                 return date.AddMonths(intervalVal.Value * 3);
         }
     }
     return date;
 }
开发者ID:cairabbit,项目名称:daf,代码行数:26,代码来源:DateTimeExtensions.cs

示例3: NextHour

 ///////////////////////////////////////////////////////////////////////
 public static DateTime NextHour(this DateTime date)
 {
     DateTime next = date.AddHours(1);
     next = next.SetMinute(0);
     next = next.SetSecond(0);
     next = next.SetMillisecond(0);
     return next;
 }
开发者ID:jheddings,项目名称:flynn,代码行数:9,代码来源:DateTimeFu.cs

示例4: ToChineseTime

 public static DateTime ToChineseTime(this DateTime dt)
 {
     //var cnOffset = TimeZoneInfo.FindSystemTimeZoneById("Asia/Shanghai").BaseUtcOffset;
     //var cnUTC = dt.Add(cnOffset);
     var cnUTC = dt.AddHours(8);
     var cnDT = new DateTime(cnUTC.Year, cnUTC.Month, cnUTC.Day, cnUTC.Hour, cnUTC.Minute, cnUTC.Second, cnUTC.Millisecond, DateTimeKind.Unspecified);
     return cnDT;
 }
开发者ID:iloveyouzlw,项目名称:MZBlog,代码行数:8,代码来源:DateTimeExtensions.cs

示例5: DateFromTimeString

        /// <summary>
        /// Return a DateTime value 
        /// </summary>
        /// <param name="dt">the current datetime</param>
        /// <param name="time">the time of day in 24-hour format (i.e. "21:30")</param>
        /// <returns></returns>
        public static DateTime DateFromTimeString(this DateTime dt, string time)
        {
            var parts = time.Split(':');
            DateTime ret = dt.AddHours(parts[0].ToDouble());
            if (parts.Length == 2)
                ret = ret.AddMinutes(parts[1].ToDouble());

            return ret;
        }
开发者ID:keith9820,项目名称:Groundfloor,代码行数:15,代码来源:DateTime.cs

示例6: ToISO8601

    public static string ToISO8601(this DateTime dt, double hourShift = 0)
    {
      string retValue = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ");

      if (dt == null)
        return retValue;

      return dt.AddHours(hourShift).ToString("yyyy-MM-ddTHH:mm:ssZ");
    }
开发者ID:aspik,项目名称:MediaPortal-2,代码行数:9,代码来源:DateTimeExtensions.cs

示例7: ConvertToUserDate

        /// <summary>
        /// 转换成用户所在时区的时间
        /// </summary>
        /// <param name="dateTime">待转换日期(UTC时间)</param>
        /// <returns>返回用户所在时区的时间</returns>
        public static DateTime ConvertToUserDate(this DateTime dateTime)
        {
            //User currentUser;
            //DateTime userDate = dt.AddHours(currentUser.Timezone);

            if (dateTime.Kind == DateTimeKind.Local)
                return dateTime;
            else
                return dateTime.AddHours(8);
        }
开发者ID:hbulzy,项目名称:SYS,代码行数:15,代码来源:DateTimeExtension.cs

示例8: DateTimeShift

 public static int DateTimeShift(this DateTime dateTime)
 {
     int hour = dateTime.AddHours(-7).Hour;
     if (hour >= 0 & hour < 9)
         return 1;
     if (hour >= 9 & hour < 16)
         return 2;
     if (hour >= 16 & hour < 24)
         return 3;
     return 1;
 }
开发者ID:AGluhov,项目名称:PmClient,代码行数:11,代码来源:EventReportViewModel.cs

示例9: RoundMinutes

        /// <summary>
        /// Rounds the minute component to the nearest specified time. Defaults to 1 hour
        /// </summary>
        /// <param name="source"></param>
        /// <param name="rounding"></param>
        /// <returns></returns>
        public static DateTime RoundMinutes(this DateTime source, MinuteRounding rounding = MinuteRounding.Hour)
        {
            if (rounding == MinuteRounding.QuarterHour)
                throw new NotImplementedException("Coming soon");

            switch (rounding)
            {
                case MinuteRounding.Hour:
                    if (source.Minute >= 30)
                        return source.AddHours(1).AddMinutes(-source.Minute).TrimSeconds();
                    return source.AddMinutes(-source.Minute).TrimSeconds();
                case MinuteRounding.HalfHour:
                    if (source.Minute < 15)
                        return source.AddMinutes(-source.Minute).TrimSeconds();
                    if (source.Minute >= 15 && source.Minute < 45)
                        return source.AddMinutes(-source.Minute).AddMinutes(30).TrimSeconds();
                    return source.AddHours(1).AddMinutes(-source.Minute).TrimSeconds();
                default:
                    throw new ArgumentOutOfRangeException("rounding");
            }
        }
开发者ID:mortware,项目名称:datafactory,代码行数:27,代码来源:Extensions.DateTime.cs

示例10: Add

 /// <summary>
 /// Adds a generic AddType to a DateTime object
 /// </summary>
 /// <param name="now"><seealso cref="System.DateTime"/></param>
 /// <param name="adder">Type structure that acts as a switcher for what type of add to perform</param>
 /// <param name="much">How much AddType to add to each element for creating list of data</param>
 /// <returns>A DateTime object with the added AddType amounts</returns>
 public static DateTime Add(this DateTime now, AddType adder, double much)
 {
     DateTime ret = now;
     switch (adder)
     {
         case AddType.Years:
             {
                 ret = now.AddYears((int)much);
                 break;
             }
         case AddType.Months:
             {
                 ret = now.AddMonths((int)much);
                 break;
             }
         case AddType.Days:
             {
                 ret = now.AddDays(much);
                 break;
             }
         case AddType.Hours:
             {
                 ret = now.AddHours(much);
                 break;
             }
         case AddType.Minutes:
             {
                 ret = now.AddMinutes(much);
                 break;
             }
         case AddType.Seconds:
             {
                 ret = now.AddSeconds(much);
                 break;
             }
         case AddType.Milliseconds:
             {
                 ret = now.AddMilliseconds(much);
                 break;
             }
         case AddType.Ticks:
             {
                 ret = now.AddTicks((long)much);
                 break;
             }
     }
     return ret;
 }
开发者ID:kLeZ,项目名称:Gecko,代码行数:55,代码来源:Extensions.cs

示例11: SubstractTimeStepUnit

 public static DateTime SubstractTimeStepUnit(this DateTime dt, TimeStepUnit tstep)
 {
   switch (tstep)
   {
     case TimeStepUnit.Year:
       return dt.AddYears(-1);
     case TimeStepUnit.Month:
       return dt.AddMonths(-1);
     case TimeStepUnit.Day:
       return dt.AddDays(-1);
     case TimeStepUnit.Hour:
       return dt.AddHours(-1);
     case TimeStepUnit.Minute:
       return dt.AddMinutes(-1);
     case TimeStepUnit.Second:
       return dt.AddSeconds(-1);
   }
   return dt;
 }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:19,代码来源:Extensions.cs

示例12: ToUtc

        public static DateTime ToUtc(this DateTime dateTime, TimeZoneInfo timeZoneInfo)
        {
            if (dateTime.Kind == DateTimeKind.Utc)
                return dateTime;

            if (timeZoneInfo == null)
                return dateTime.ToUniversalTime();

            var offSet1 = new DateTimeOffset(dateTime);
            var utcDateTime = dateTime.ToUniversalTime();
            var tzDate = utcDateTime.ToTimeZone(timeZoneInfo);

            var offSet2 = new DateTimeOffset(tzDate);

            var offSet3 = offSet1 - offSet2;
            var date = dateTime.AddHours(offSet3.Hours);

            return date.ToUniversalTime();
        }
开发者ID:ukionik,项目名称:StoreEngine,代码行数:19,代码来源:DateTimeExtensions.cs

示例13: SubtractHours

 /// <summary>
 /// Subtracts given hours from the given DateTime.
 /// </summary>
 /// <param name="date">The given DateTime.</param>
 /// <param name="hours">Number of hours to be subtracted.</param>
 /// <returns>The DateTime after the given hours are subtracted.</returns>
 public static DateTime SubtractHours(this DateTime date, int hours)
 {
     return date.AddHours(hours.Negate());
 }
开发者ID:rocketgames,项目名称:Extension-Methods-for-Unity,代码行数:10,代码来源:DateTimeExtensions.cs

示例14: AddAnHour

 /// <summary>
 /// Adds one hour to the given DateTime.
 /// </summary>
 /// <param name="date">The given DateTime.</param>
 /// <returns>The DateTime after one hour is added.</returns>
 public static DateTime AddAnHour(this DateTime date)
 {
     return date.AddHours(1);
 }
开发者ID:rocketgames,项目名称:Extension-Methods-for-Unity,代码行数:9,代码来源:DateTimeExtensions.cs

示例15: SubtractHours

 public static DateTime SubtractHours(this DateTime dateTime, double hours)
 {
     return dateTime.AddHours(-hours);
 }
开发者ID:JonasSamuelsson,项目名称:Handyman,代码行数:4,代码来源:DateTimeExtensions.cs


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