• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# DateTimeKind类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中DateTimeKind的典型用法代码示例。如果您正苦于以下问题:C# DateTimeKind类的具体用法?C# DateTimeKind怎么用?C# DateTimeKind使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DateTimeKind类属于命名空间,在下文中一共展示了DateTimeKind类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: DoTest

		private static void DoTest(DateTime dt, DateTimeKind inKind, DateTimeKind outKind)
		{
			Assert.Equal(inKind, dt.Kind);

			using (var documentStore = new EmbeddableDocumentStore { RunInMemory = true })
			{
				documentStore.Initialize();

				using (var session = documentStore.OpenSession())
				{
					session.Store(new Foo { Id = "foos/1", DateTime = dt });
					session.SaveChanges();
				}

				using (var session = documentStore.OpenSession())
				{
					var foo = session.Query<Foo>()
									 .Customize(x => x.WaitForNonStaleResults())
									 .FirstOrDefault(x => x.DateTime == dt);

					WaitForUserToContinueTheTest(documentStore);

					Assert.Equal(dt, foo.DateTime);
					Assert.Equal(outKind, foo.DateTime.Kind);
				}
			}
		}
开发者ID:925coder,项目名称:ravendb,代码行数:27,代码来源:DateTime_QueryDynamicTests.cs


示例2: GetDateInUserTimeZone

 public static DateTime GetDateInUserTimeZone(DateTime sourceDate, DateTimeKind sourceDateTimeKind, User user)
 {
     sourceDate = DateTime.SpecifyKind(sourceDate, sourceDateTimeKind);
     //get the timezone of mentioned user
     var userTimezoneId = user.GetPropertyValueAs<string>(PropertyNames.DefaultTimeZoneId);
     if (string.IsNullOrEmpty(userTimezoneId))
     {
         //get default timezone
         var generalSettings = mobSocialEngine.ActiveEngine.Resolve<GeneralSettings>();
         userTimezoneId = generalSettings.DefaultTimeZoneId;
     }
     //let's find the timezone
     TimeZoneInfo timeZoneInfo;
     try
     {
         timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(userTimezoneId);
     }
     catch
     {
         //in case of error let's default to local timezone
         timeZoneInfo = TimeZoneInfo.Local;
     }
     //get the timezone
     return GetDateInTimeZone(sourceDate, timeZoneInfo);
 }
开发者ID:mobsoftware,项目名称:mobsocial,代码行数:25,代码来源:DatetimeHelper.cs


示例3: DateParser

        public DateParser(string format, DateTimeKind kind)
        {
            switch (kind)
            {
                case DateTimeKind.Local:
                    _style = DateTimeStyles.AssumeLocal;
                    break;

                case DateTimeKind.Utc:
                    _style = DateTimeStyles.AssumeUniversal;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("kind");
            }

            switch (format)
            {
                case "ABSOLUTE":
                    break;

                case "ISO8601":
                    break;

                case "DATE":
                    break;
            }
        }
开发者ID:Kittyfisto,项目名称:Tailviewer,代码行数:28,代码来源:DateParser.cs


示例4: GetMinValue

        /// <summary>
        /// Gets the Minimum value for a DateTime specifying kind.
        /// </summary>
        /// <param name="kind">DateTimeKind to use.</param>
        /// <returns>DateTime of specified kind.</returns>
        public static DateTime GetMinValue(DateTimeKind kind)
        {
            if (kind == DateTimeKind.Unspecified)
                return new DateTime(DateTime.MinValue.Ticks, DateTimeKind.Utc);

            return new DateTime(DateTime.MinValue.Ticks, kind);
        }
开发者ID:vebin,项目名称:azure-activedirectory-identitymodel-extensions-for-dotnet,代码行数:12,代码来源:DateTimeUtil.cs


示例5: Compare

        /// <summary>
        /// 現在のインスタンスと比較します。
        /// </summary>
        /// <param name="self">自分自身</param>
        /// <param name="value">比較する値</param>
        /// <param name="compareKind">比較する時間の種別</param>
        /// <returns>比較結果(true:一致, false:不一致)</returns>
        public static bool Compare(this DateTime self, DateTime value, DateTimeKind compareKind)
        {
            var ts = self - value;
            double total = 0D;
            double sub = 1.0D;

            switch (compareKind)
            {
                case DateTimeKind.Year:
                    total = self.Year - value.Year;
                    break;
                case DateTimeKind.Month:
                    sub = 30.0D;
                    total = ts.TotalDays;
                    break;
                case DateTimeKind.Day:
                    total = ts.TotalDays;
                    break;
                case DateTimeKind.Hour:
                    total = ts.TotalHours;
                    break;
                case DateTimeKind.Minute:
                    total = ts.TotalMinutes;
                    break;
                case DateTimeKind.Second:
                    total = ts.TotalSeconds;
                    break;
                case DateTimeKind.Milliseconds:
                    total = ts.TotalMilliseconds;
                    break;
            }

            return Math.Abs(total) < sub;
        }
开发者ID:Iyemon-018,项目名称:Dev,代码行数:41,代码来源:DateTimeExtensions.cs


示例6: SetPosition

 public void SetPosition(DateTime when, DateTimeKind whenKind, double latitudeDegrees, double longitudeDegrees)
 {
   IntPtr pSun = NonConstPointer();
   UnsafeNativeMethods.Rdk_Sun_SetLatitudeLongitude(pSun, latitudeDegrees, longitudeDegrees);
   bool local = whenKind != DateTimeKind.Utc;
   UnsafeNativeMethods.Rdk_Sun_SetDateTime(pSun, local, when.Year, when.Month, when.Day, when.Hour, when.Minute, when.Second);
 }
开发者ID:austinlaw,项目名称:rhinocommon,代码行数:7,代码来源:sun.cs


示例7: DateTimeSerializationOptions

 /// <summary>
 /// Initializes a new instance of the DateTimeSerializationOptions class.
 /// </summary>
 /// <param name="kind">The DateTimeKind (Local, Unspecified or Utc).</param>
 /// <param name="representation">The external representation.</param>
 public DateTimeSerializationOptions(
     DateTimeKind kind,
     BsonType representation
 ) {
     this.kind = kind;
     this.representation = representation;
 }
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:12,代码来源:DateTimeSerializationOptions.cs


示例8: DateTimeRule

 /// <summary>
 /// Initializes a new instance of the <see cref="UserDataRule" /> class.
 /// </summary>
 /// <param name="columnName">Name of the column.</param>
 /// <param name="kind">The kind.</param>
 /// <param name="appliesWhen">The rule can be applied to insert, update, and/or soft delete operations.</param>
 /// <exception cref="ArgumentOutOfRangeException">appliesWhen;appliesWhen may only be a combination of Insert, Update, or Delete</exception>
 /// <remarks>
 /// This will have no effect on hard deletes.
 /// </remarks>
 public DateTimeRule(string columnName, DateTimeKind kind, OperationTypes appliesWhen) : base(columnName, appliesWhen)
 {
     if (appliesWhen.HasFlag(OperationTypes.Select))
         throw new ArgumentOutOfRangeException("appliesWhen", appliesWhen, "appliesWhen may only be a combination of Insert, Update, or Delete");
     if (kind == DateTimeKind.Unspecified)
         throw new ArgumentOutOfRangeException("kind");
     Kind = kind;
 }
开发者ID:docevaad,项目名称:Chain,代码行数:18,代码来源:DateTimeRule.cs


示例9: LoadJPEG

 public static SharpMapillaryInfo LoadJPEG(this SharpMapillaryInfo           MapillaryInfo,
                                           String                            JPEGFile,
                                           DateTimeKind                      DateTimeType         = DateTimeKind.Utc,
                                           Int32?                            TimeOffset           = null,
                                           Func<String, DateTime, DateTime>  OnDupliateTimestamp  = null)
 {
     return LoadJPEG(JPEGFile, ref MapillaryInfo, DateTimeType, TimeOffset, OnDupliateTimestamp);
 }
开发者ID:GraphDefined,项目名称:SharpMapillary,代码行数:8,代码来源:LoadJPGs.cs


示例10: BsonReader

 /// <summary>
 /// Initializes a new instance of the <see cref="BsonReader"/> class.
 /// </summary>
 /// <param name="stream">The stream.</param>
 /// <param name="readRootValueAsArray">if set to <c>true</c> the root object will be read as a JSON array.</param>
 /// <param name="dateTimeKindHandling">The <see cref="DateTimeKind" /> used when reading <see cref="DateTime"/> values from BSON.</param>
 public BsonReader(Stream stream, bool readRootValueAsArray, DateTimeKind dateTimeKindHandling)
 {
     ValidationUtils.ArgumentNotNull(stream, "stream");
     _reader = new BinaryReader(stream);
     _stack = new List<ContainerContext>();
     _readRootValueAsArray = readRootValueAsArray;
     _dateTimeKindHandling = dateTimeKindHandling;
 }
开发者ID:ThePiachu,项目名称:BitNet,代码行数:14,代码来源:BsonReader.cs


示例11: DateTimeDataType

 public DateTimeDataType(int id, string name, string alias, DataType basic, DataType parent, bool editable,
     DateTimeKind part, DateTime minValue, DateTime maxValue, bool nullable)
     : base(id, name, alias, basic, parent, editable, nullable)
 {
     this.part = part;
     this.minValue = minValue;
     this.maxValue = maxValue;
 }
开发者ID:jihadbird,项目名称:firespider,代码行数:8,代码来源:DateTimeDataType.cs


示例12: FromSortableIntDateTime

        /// <summary>
        ///     Returns DateTime created from an integer in the YYYYMMDD, YYYYMMDDHHmmss, or YYYYMMDDHHmmssFFF format.
        /// </summary>
        /// <param name="sortableDateTime"></param>
        /// <param name="dtKind"></param>
        /// <returns></returns>
        public static DateTime? FromSortableIntDateTime(this string sortableDateTime, DateTimeKind dtKind = DateTimeKind.Unspecified)
        {
            long? sortableVal = sortableDateTime.ParseLong();
            if(sortableVal == null)
                return null;

            return sortableVal.Value.FromSortableIntDateTime(dtKind);
        }
开发者ID:vgribok,项目名称:Aspectacular,代码行数:14,代码来源:DateTimeExtensions.cs


示例13: GetDateTime

        /// <summary>
        /// Obtient une date dans le kind spécifié en fonction des paramètres spécifiés
        /// </summary>
        /// <param name="rule"><see cref="RuleDate"/> décrivant la date</param>
        /// <param name="year">Année de la date</param>
        /// <param name="gmtOffset">Offset gmt dans lequel est exprimé la date</param>
        /// <param name="stdOffset">Offset standard dans lequel est exprimé la date</param>
        /// <param name="dateTimeKind"><see cref="DateTimeKind"/> dans lequel exprimer la date</param>
        /// <returns><see cref="DateTime"/> du kind spécifié correspondant aux paramètres spécifiés</returns>
        public static DateTime GetDateTime(RuleDate rule, int year, TimeSpan gmtOffset, TimeSpan stdOffset, DateTimeKind dateTimeKind)
        {
            if (dateTimeKind == DateTimeKind.Unspecified) throw new ArgumentException("Unspecified date time kind", "dateTimeKind");

            if (dateTimeKind == DateTimeKind.Local)
                return GetWallClockTime(rule, year, gmtOffset, stdOffset);
            return GetUTCTime(rule, year, gmtOffset, stdOffset);
        }
开发者ID:LZorglub,项目名称:TimeZone,代码行数:17,代码来源:TzUtilities.cs


示例14: __DateTime

        public __DateTime()
        {
            this.Kind = DateTimeKind.Local;
            // fix for default(DateTime).ToString
            // X:\jsc.svn\examples\javascript\Test\TestDateTime\TestDateTime\Program.cs
            this.InternalValue = new IDate();

        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:8,代码来源:DateTime.cs


示例15: GetCurrentTime

 public DateTime GetCurrentTime(DateTimeKind dateTimeKind)
 {
     switch (dateTimeKind)
     {
         case DateTimeKind.Local: return DateTime.Now.ToLocalTime();
         case DateTimeKind.Utc: return DateTime.Now.ToUniversalTime();
         default: return DateTime.Now;
     }
 }
开发者ID:ittray,项目名称:LocalDemo,代码行数:9,代码来源:DefaultTimeProvider.cs


示例16: GetContextNow

    public static DateTime GetContextNow( DateTimeKind kind )
    {
      if( kind == DateTimeKind.Unspecified )
        return DateTime.SpecifyKind( DateTime.Now, DateTimeKind.Unspecified );

      return ( kind == DateTimeKind.Utc )
        ? DateTime.UtcNow
        : DateTime.Now;
    }
开发者ID:Gainedge,项目名称:BetterExplorer,代码行数:9,代码来源:DateTimeUtilities.cs


示例17: SpecifyKindIfUnspecified

        public static DateTime? SpecifyKindIfUnspecified(DateTime? dateTime, DateTimeKind kind)
        {
            if (dateTime == null)
            {
                return null;
            }

            return dateTime.Value.Kind == DateTimeKind.Unspecified ? DateTime.SpecifyKind(dateTime.Value, kind) : dateTime;
        }
开发者ID:ciker,项目名称:Shaolinq,代码行数:9,代码来源:UniversalTimeNormalisingDateTimeSqlDateType.cs


示例18: DateTimeWithZone

        public DateTimeWithZone(DateTime dateTime, TimeZoneInfo timeZone, DateTimeKind kind = DateTimeKind.Utc)
        {
            dateTime = DateTime.SpecifyKind(dateTime, kind);

            utcDateTime = dateTime.Kind != DateTimeKind.Utc
                            ? TimeZoneInfo.ConvertTimeToUtc(dateTime, timeZone)
                            : dateTime;

            this.timeZone = timeZone;
        }
开发者ID:isyedakhtar,项目名称:Fabrik.Common,代码行数:10,代码来源:DateTimeWithZone.cs


示例19: ToUnixTime

 /// <summary>
 /// DateTime을 Unix timestamp로 반환합니다.
 /// </summary>
 /// <param name="date">변환할 DateTime</param>
 /// <param name="includeMilliseconds">밀리초 단위인지 여부</param>
 /// <param name="kind">DateTime의 종류</param>
 /// <returns>변환된 Unix timestamp</returns>
 public static long ToUnixTime(this DateTime date, bool includeMilliseconds = true, DateTimeKind kind = DateTimeKind.Utc)
 {
     var epoch = new DateTime(1970, 1, 1, 0, 0, 0, kind);
     var diff = includeMilliseconds ? (date - epoch).TotalMilliseconds : (date - epoch).TotalSeconds;
     #if DNXCORE50
     return (long)diff;
     #else
     return (long)Math.Floor(diff);
     #endif
 }
开发者ID:OpenBapul,项目名称:iamport-rest-client-net,代码行数:17,代码来源:UnixDateTimeExtensions.cs


示例20: ToLocalTime

 /// <summary>
 /// Converts a DateTime to local time (with special handling for MinValue and MaxValue).
 /// </summary>
 /// <param name="dateTime">A DateTime.</param>
 /// <param name="kind">A DateTimeKind.</param>
 /// <returns>The DateTime in local time.</returns>
 public static DateTime ToLocalTime(DateTime dateTime, DateTimeKind kind)
 {
     if (dateTime.Kind == kind) return dateTime;
     else
     {
         if (dateTime == DateTime.MinValue) return DateTime.SpecifyKind(DateTime.MinValue, kind);
         else if (dateTime == DateTime.MaxValue) return DateTime.SpecifyKind(DateTime.MaxValue, kind);
         else return DateTime.SpecifyKind(dateTime.ToLocalTime(), kind);
     }
 }
开发者ID:htlp,项目名称:FastSocket.Net,代码行数:16,代码来源:Date.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DateTimeOffset类代码示例发布时间:2022-05-24
下一篇:
C# DateTimeFormatInfo类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap