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


C# DateTime.AsDateTime方法代码示例

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


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

示例1: IncludeHours_WhenInvoked_ShouldIncludeHours

 public void IncludeHours_WhenInvoked_ShouldIncludeHours(DateTime subject)
 {
     subject.AsDateTime().IncludeHours().With12HrSingleDigit().Format().ShouldEqual(subject.ToString("%h"));
     subject.AsDateTime().IncludeHours().With12HrDoubleDigit().Format().ShouldEqual(subject.ToString("hh"));
     subject.AsDateTime().IncludeHours().With24HrSingleDigit().Format().ShouldEqual(subject.ToString("%H"));
     subject.AsDateTime().IncludeHours().With24HrDoubleDigit().Format().ShouldEqual(subject.ToString("HH"));
 }
开发者ID:TheCrow1213,项目名称:WithFormat,代码行数:7,代码来源:DateTimeFormatTests.cs

示例2: IncludeMilliseconds_WhenInvoked_ShouldIncludeMillisecondsInString

        public void IncludeMilliseconds_WhenInvoked_ShouldIncludeMillisecondsInString(DateTime subject)
        {
            subject.AsDateTime().IncludeMilliSeconds().InTenthsOfASecond().Format().ShouldEqual(subject.ToString("%f"));
            subject.AsDateTime().IncludeMilliSeconds().InHundredthsOfASecond().Format().ShouldEqual(subject.ToString("ff"));
            subject.AsDateTime().IncludeMilliSeconds().InMilliseconds().Format().ShouldEqual(subject.ToString("fff"));
            subject.AsDateTime().IncludeMilliSeconds().InTenThousandthsOfASecond().Format().ShouldEqual(subject.ToString("ffff"));
            subject.AsDateTime().IncludeMilliSeconds().InHundredThousandthsOfASecond().Format().ShouldEqual(subject.ToString("fffff"));
            subject.AsDateTime().IncludeMilliSeconds().InMillionthsOfASecond().Format().ShouldEqual(subject.ToString("ffffff"));
            subject.AsDateTime().IncludeMilliSeconds().InTenMillionthsOfASecond().Format().ShouldEqual(subject.ToString("fffffff"));

            subject.AsDateTime().IncludeMilliSeconds().InTenthsOfASecondWithoutZeroes().Format().ShouldEqual(subject.ToString("%F"));
            subject.AsDateTime().IncludeMilliSeconds().InHundredthsOfASecondWithoutZeroes().Format().ShouldEqual(subject.ToString("FF"));
            subject.AsDateTime().IncludeMilliSeconds().InMillisecondsWithoutZeroes().Format().ShouldEqual(subject.ToString("FFF"));
            subject.AsDateTime().IncludeMilliSeconds().InTenThousandthsOfASecondWithoutZeroes().Format().ShouldEqual(subject.ToString("FFFF"));
            subject.AsDateTime().IncludeMilliSeconds().InHundredThousandthsOfASecondWithoutZeroes().Format().ShouldEqual(subject.ToString("FFFFF"));
            subject.AsDateTime().IncludeMilliSeconds().InMillionthsOfASecondWithoutZeroes().Format().ShouldEqual(subject.ToString("FFFFFF"));
            subject.AsDateTime().IncludeMilliSeconds().InTenMillionthsOfASecondWithoutZeroes().Format().ShouldEqual(subject.ToString("FFFFFFF"));
        }
开发者ID:TheCrow1213,项目名称:WithFormat,代码行数:18,代码来源:DateTimeFormatTests.cs

示例3: IncludeAmPmSpecifier_WhenInvoked_ShouldIncludeAmOrPm

 public void IncludeAmPmSpecifier_WhenInvoked_ShouldIncludeAmOrPm(DateTime subject)
 {
     subject.AsDateTime().IncludeAmPmSpecifier().WithSingleCharacter().Format().ShouldEqual(subject.ToString("%t"));
     subject.AsDateTime().IncludeAmPmSpecifier().WithTwoCharacters().Format().ShouldEqual(subject.ToString("tt"));
 }
开发者ID:TheCrow1213,项目名称:WithFormat,代码行数:5,代码来源:DateTimeFormatTests.cs

示例4: WithTwoDigits_WhenInvoked_ShouldReturnTwoDigitYear

 public void WithTwoDigits_WhenInvoked_ShouldReturnTwoDigitYear(DateTime subject)
 {
     subject.AsDateTime().IncludeYear().WithTwoDigits().Format().ShouldEqual(subject.ToString("yy"));
 }
开发者ID:TheCrow1213,项目名称:WithFormat,代码行数:4,代码来源:DateTimeFormatTests.cs

示例5: WithTwoDigitMonth_WhenInvoked_ShouldReturnTwoDigitMonth

 public void WithTwoDigitMonth_WhenInvoked_ShouldReturnTwoDigitMonth(DateTime subject)
 {
     subject.AsDateTime().IncludeMonth().WithTwoDigitMonth().Format().ShouldEqual(subject.ToString("MM"));
 }
开发者ID:TheCrow1213,项目名称:WithFormat,代码行数:4,代码来源:DateTimeFormatTests.cs

示例6: WithNumericMonth_WhenInvoked_ShouldReturnNumericMonth

 public void WithNumericMonth_WhenInvoked_ShouldReturnNumericMonth(DateTime subject)
 {
     subject.AsDateTime().IncludeMonth().WithNumericMonth().Format().ShouldEqual(subject.ToString("%M"));
 }
开发者ID:TheCrow1213,项目名称:WithFormat,代码行数:4,代码来源:DateTimeFormatTests.cs

示例7: WithFullDayOfWeek_WhenInvoked_ShouldReturnFullDayOfWeek

 public void WithFullDayOfWeek_WhenInvoked_ShouldReturnFullDayOfWeek(DateTime subject)
 {
     subject.AsDateTime().IncludeDay().WithFullDayOfWeek().Format().ShouldEqual(subject.ToString("dddd"));
 }
开发者ID:TheCrow1213,项目名称:WithFormat,代码行数:4,代码来源:DateTimeFormatTests.cs

示例8: IncludeSeconds_WhenInvoked_ShouldIncludeFormattedSeconds

 public void IncludeSeconds_WhenInvoked_ShouldIncludeFormattedSeconds(DateTime subject)
 {
     subject.AsDateTime().IncludeSeconds().AsSingleDigit().Format().ShouldEqual(subject.ToString("%s"));
     subject.AsDateTime().IncludeSeconds().AsDoubleDigit().Format().ShouldEqual(subject.ToString("ss"));
 }
开发者ID:TheCrow1213,项目名称:WithFormat,代码行数:5,代码来源:DateTimeFormatTests.cs

示例9: WithDelimiter_WhenInvoked_ShouldReturnStringFormattedWithDelimiter

 public void WithDelimiter_WhenInvoked_ShouldReturnStringFormattedWithDelimiter(DateTime subject)
 {
     subject.AsDateTime().UsingDelimiter(" : ").IncludeYear().WithFourDigits().IncludeMonth().WithAbbreviatedMonth().Format().ShouldEqual(subject.ToString("yyyy : MMM"));
     subject.AsDateTime().UsingDelimiter("/").IncludeYear().WithFourDigits().IncludeMonth().WithAbbreviatedMonth().Format().ShouldEqual(subject.ToString("yyyy/MMM"));
     subject.AsDateTime().UsingDelimiter("-").IncludeYear().WithFourDigits().IncludeMonth().WithAbbreviatedMonth().Format().ShouldEqual(subject.ToString("yyyy-MMM"));
     subject.AsDateTime().UsingDelimiter("+").IncludeYear().WithFourDigits().IncludeMonth().WithAbbreviatedMonth().Format().ShouldEqual(subject.ToString("yyyy+MMM"));
     subject.AsDateTime().UsingDelimiter(" ").IncludeYear().WithFourDigits().IncludeMonth().WithAbbreviatedMonth().Format().ShouldEqual(subject.ToString("yyyy MMM"));
     subject.AsDateTime().UsingDelimiter("t").IncludeYear().WithFourDigits().IncludeMonth().WithAbbreviatedMonth().Format().ShouldEqual(subject.ToString("yyyy\\tMMM"));
 }
开发者ID:TheCrow1213,项目名称:WithFormat,代码行数:9,代码来源:DateTimeFormatTests.cs

示例10: WithAtLeastOneDigit_WhenInvoked_ShouldReturnOneDigit

 public void WithAtLeastOneDigit_WhenInvoked_ShouldReturnOneDigit(DateTime subject)
 {
     subject.AsDateTime().IncludeDay().WithAtLeastOneDigit().Format().ShouldEqual(subject.ToString("%d"));
 }
开发者ID:TheCrow1213,项目名称:WithFormat,代码行数:4,代码来源:DateTimeFormatTests.cs

示例11: WithAbbrebiatedMonth_WhenInvoked_ShouldReturnAbbreviatedMonth

 public void WithAbbrebiatedMonth_WhenInvoked_ShouldReturnAbbreviatedMonth(DateTime subject)
 {
     subject.AsDateTime().IncludeMonth().WithAbbreviatedMonth().Format().ShouldEqual(subject.ToString("MMM"));
 }
开发者ID:TheCrow1213,项目名称:WithFormat,代码行数:4,代码来源:DateTimeFormatTests.cs

示例12: InsertCustomDelimiter_WhenInvoked_ShouldInsertDelimiterAtSpecifiedPoint

        public void InsertCustomDelimiter_WhenInvoked_ShouldInsertDelimiterAtSpecifiedPoint(DateTime subject)
        {
            subject.AsDateTime()
                .IncludeYear().WithFourDigits().InsertCustomDelimiter(", ")
                .IncludeMonth().WithFullMonth()
                .IncludeDay().WithAtLeastOneDigit()
                .Format().ShouldEqual(subject.ToString("yyyy, MMMM d"));

            subject.AsDateTime()
                .IncludeYear().WithFourDigits()
                .IncludeMonth().WithFullMonth().InsertCustomDelimiter(":")
                .IncludeDay().WithAtLeastOneDigit()
                .Format().ShouldEqual(subject.ToString("yyyy MMMM:d"));

            subject.AsDateTime()
                .IncludeYear().WithFourDigits()
                .IncludeMonth().WithFullMonth()
                .IncludeDay().WithAtLeastOneDigit().InsertCustomDelimiter("!")
                .Format().ShouldEqual(subject.ToString("yyyy MMMM d!"));

            subject.AsDateTime()
                .IncludeYear().WithFourDigits()
                .IncludeMonth().WithFullMonth()
                .IncludeDay().WithAtLeastOneDigit().InsertCustomDelimiter("t")
                .Format().ShouldEqual(subject.ToString("yyyy MMMM d\\t"));
        }
开发者ID:TheCrow1213,项目名称:WithFormat,代码行数:26,代码来源:DateTimeFormatTests.cs

示例13: IncludeUtcOffset_WhenInvoked_ShouldIncludeUtcOffset

 public void IncludeUtcOffset_WhenInvoked_ShouldIncludeUtcOffset(DateTime subject)
 {
     subject.AsDateTime().IncludeUtcOffset().WithSingleDigitHours().Format().ShouldEqual(subject.ToString("%z"));
     subject.AsDateTime().IncludeUtcOffset().WithDoubleDigitHours().Format().ShouldEqual(subject.ToString("zz"));
     subject.AsDateTime().IncludeUtcOffset().WithHourAndMinutesOffset().Format().ShouldEqual(subject.ToString("zzz"));
 }
开发者ID:TheCrow1213,项目名称:WithFormat,代码行数:6,代码来源:DateTimeFormatTests.cs

示例14: IncludeTimeZone_WhenInvoked_ShouldIncludeTimeZone

 public void IncludeTimeZone_WhenInvoked_ShouldIncludeTimeZone(DateTime subject)
 {
     subject.AsDateTime().IncludeTimeZone().Format().ShouldEqual(subject.ToString("%K"));
 }
开发者ID:TheCrow1213,项目名称:WithFormat,代码行数:4,代码来源:DateTimeFormatTests.cs

示例15: IncludeTimePeriod_WhenInvoked_ShouldIncludeTimePeriod

 public void IncludeTimePeriod_WhenInvoked_ShouldIncludeTimePeriod(DateTime subject)
 {
     subject.AsDateTime().IncludeTimePeriod().Format().ShouldEqual(subject.ToString("%g"));
 }
开发者ID:TheCrow1213,项目名称:WithFormat,代码行数:4,代码来源:DateTimeFormatTests.cs


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