本文整理汇总了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"));
}
示例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"));
}
示例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"));
}
示例4: WithTwoDigits_WhenInvoked_ShouldReturnTwoDigitYear
public void WithTwoDigits_WhenInvoked_ShouldReturnTwoDigitYear(DateTime subject)
{
subject.AsDateTime().IncludeYear().WithTwoDigits().Format().ShouldEqual(subject.ToString("yy"));
}
示例5: WithTwoDigitMonth_WhenInvoked_ShouldReturnTwoDigitMonth
public void WithTwoDigitMonth_WhenInvoked_ShouldReturnTwoDigitMonth(DateTime subject)
{
subject.AsDateTime().IncludeMonth().WithTwoDigitMonth().Format().ShouldEqual(subject.ToString("MM"));
}
示例6: WithNumericMonth_WhenInvoked_ShouldReturnNumericMonth
public void WithNumericMonth_WhenInvoked_ShouldReturnNumericMonth(DateTime subject)
{
subject.AsDateTime().IncludeMonth().WithNumericMonth().Format().ShouldEqual(subject.ToString("%M"));
}
示例7: WithFullDayOfWeek_WhenInvoked_ShouldReturnFullDayOfWeek
public void WithFullDayOfWeek_WhenInvoked_ShouldReturnFullDayOfWeek(DateTime subject)
{
subject.AsDateTime().IncludeDay().WithFullDayOfWeek().Format().ShouldEqual(subject.ToString("dddd"));
}
示例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"));
}
示例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"));
}
示例10: WithAtLeastOneDigit_WhenInvoked_ShouldReturnOneDigit
public void WithAtLeastOneDigit_WhenInvoked_ShouldReturnOneDigit(DateTime subject)
{
subject.AsDateTime().IncludeDay().WithAtLeastOneDigit().Format().ShouldEqual(subject.ToString("%d"));
}
示例11: WithAbbrebiatedMonth_WhenInvoked_ShouldReturnAbbreviatedMonth
public void WithAbbrebiatedMonth_WhenInvoked_ShouldReturnAbbreviatedMonth(DateTime subject)
{
subject.AsDateTime().IncludeMonth().WithAbbreviatedMonth().Format().ShouldEqual(subject.ToString("MMM"));
}
示例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"));
}
示例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"));
}
示例14: IncludeTimeZone_WhenInvoked_ShouldIncludeTimeZone
public void IncludeTimeZone_WhenInvoked_ShouldIncludeTimeZone(DateTime subject)
{
subject.AsDateTime().IncludeTimeZone().Format().ShouldEqual(subject.ToString("%K"));
}
示例15: IncludeTimePeriod_WhenInvoked_ShouldIncludeTimePeriod
public void IncludeTimePeriod_WhenInvoked_ShouldIncludeTimePeriod(DateTime subject)
{
subject.AsDateTime().IncludeTimePeriod().Format().ShouldEqual(subject.ToString("%g"));
}