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


C# DateTimeOffset.GetValueOrDefault方法代码示例

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


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

示例1: Dates

        /// <summary>
        /// Returns random datetimeoffset gen
        /// </summary>
        /// <param name="min">if not supplied, DateTimeOffset.MinValue is used</param>
        /// <param name="max">if not supplied, DateTimeOffset.MaxValue is used</param>
        public Func<DateTimeOffset> Dates(DateTimeOffset? min = null, DateTimeOffset? max = null)
        {
            var minDate = min.GetValueOrDefault(DateTimeOffset.MinValue);
            var maxDate = max.GetValueOrDefault(DateTimeOffset.MaxValue);

            if (minDate >= maxDate)
                throw new ArgumentOutOfRangeException("min >= max");

            var ticksSpan = maxDate.Ticks - minDate.Ticks;
            var factory = _random.Numbers.Doubles().BetweenZeroAndOne();

            return () => new DateTimeOffset(Convert.ToInt64(minDate.Ticks + ((double)ticksSpan * factory())), minDate.Offset);
        }
开发者ID:aliostad,项目名称:RandomGen,代码行数:18,代码来源:TimeLink.cs

示例2: GetTransactionsToComputeAccountTotal

        public IEnumerable<TransactionsToComputeAccountTotal> GetTransactionsToComputeAccountTotal(DateTimeOffset startDate, DateTimeOffset? endDate = null)
        {
            if (endDate == null)
            {
                endDate = DateTime.Now;
            }

            string dateFormat = "yyyy-MM-dd";
            string query = @"
                                SELECT * FROM [dbo].[TransactionsToComputeAccountTotal] (@startDate, @endDate)
                            ";

            string sd = startDate.Date.ToString(dateFormat);
            string ed = endDate.GetValueOrDefault().Date.ToString(dateFormat);

            return this.context.Database.SqlQuery<TransactionsToComputeAccountTotal>(query,
                new SqlParameter("@startDate", sd),
                new SqlParameter("@endDate", ed)
                );
        }
开发者ID:joelmccune,项目名称:ChurchManager,代码行数:20,代码来源:SQLQueryRepository.cs

示例3: Run

        /// <summary>
        /// Runs the specified date time.
        /// </summary>
        /// <param name="dateTime">The date time</param>
        public void Run(DateTimeOffset? dateTime = null)
        {
            DateTimeOffset now = dateTime.GetValueOrDefault(DateTimeOffset.UtcNow);

            if (now > this.Recurrence.DateEnd)
            {
                this.Status = TaskItemStatus.Stopped;
                return;
            }

            if (!this.Recurrence.CheckDate(now))
            {
                return;
            }

            if (this.Status != TaskItemStatus.Running)
            {
                return;
            }
            else if (now.Subtract(this.LastRun) < this.Recurrence.Interval)
            {
                return;
            }

            this.LastRun = now;

            CancellationTokenSource cancellationTokenSource;
            if (this.Lifetime != TimeSpan.Zero)
            {
                cancellationTokenSource = new CancellationTokenSource(this.Lifetime);
            }
            else
            {
                cancellationTokenSource = new CancellationTokenSource();
            }

            TaskActionParameters cronActionParameters = new TaskActionParameters(this, now, cancellationTokenSource);
            this.ActiveActions.Add(cronActionParameters);

            Action actionToRun = () =>
            {
                for (int i = this.Repeat; i > 0; i--) {
                    this.Action(cronActionParameters);
                }
                this.ActiveActions.Remove(cronActionParameters);
            };

            Task lastTask = Task.Run(actionToRun, cancellationTokenSource.Token);

            if (this.Recurrence.Interval == TimeSpan.Zero)
            {
                this.Status = TaskItemStatus.Stopped;
            }
        }
开发者ID:eserozvataf,项目名称:tasslehoff,代码行数:58,代码来源:TaskItem.cs

示例4: WriteValue

 /// <summary>
 /// Writes a <see cref="Nullable{DateTimeOffset}"/> value.
 /// </summary>
 /// <param name="value">The <see cref="Nullable{DateTimeOffset}"/> value to write.</param>
 public virtual void WriteValue(DateTimeOffset? value)
 {
     if (value == null)
     {
         WriteNull();
     }
     else
     {
         WriteValue(value.GetValueOrDefault());
     }
 }
开发者ID:cilliemalan,项目名称:Cargo,代码行数:15,代码来源:JsonWriter.cs

示例5: WriteValue

 /// <summary>
 /// Writes a <see cref="Nullable{DateTimeOffset}"/> value.
 /// </summary>
 /// <param name="value">The <see cref="Nullable{DateTimeOffset}"/> value to write.</param>
 public virtual void WriteValue(DateTimeOffset? value, string format = null) {
     if (value == null) {
         WriteNull();
     } else {
         WriteValue(value.GetValueOrDefault(), format);
     }
 }
开发者ID:indice-co,项目名称:EDI.Net,代码行数:11,代码来源:EdiWriter.cs

示例6: UnixTimestamp

 // methods
 /// <summary>
 /// Converts to Unix Timestamp.
 /// </summary>
 /// <param name="datetime">DateTime to be converted</param>
 /// <returns>Unix Timestamp</returns>
 public static double UnixTimestamp(DateTimeOffset? datetime)
 {
     DateTimeOffset epoch = new DateTimeOffset(1970, 1, 1, 0, 0, 0, 0, TimeSpan.Zero);
     return (datetime.GetValueOrDefault(DateTimeOffset.UtcNow) - epoch).TotalSeconds;
 }
开发者ID:eserozvataf,项目名称:tasslehoff,代码行数:11,代码来源:DateTimeHelpers.cs


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