本文整理汇总了C#中System.DateTime.SetYearSafe方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.SetYearSafe方法的具体用法?C# DateTime.SetYearSafe怎么用?C# DateTime.SetYearSafe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DateTime
的用法示例。
在下文中一共展示了DateTime.SetYearSafe方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetYearSafe_preserves_second
public void SetYearSafe_preserves_second()
{
var dateTime = new DateTime(2014, 7, 7, 22, 32, 46);
var actual = dateTime.SetYearSafe(2015);
Assert.AreEqual(dateTime.Second, actual.Second);
}
示例2: SetYearSafe_preserves_minute
public void SetYearSafe_preserves_minute()
{
var dateTime = new DateTime(2014, 7, 7, 22, 32, 46);
var actual = dateTime.SetYearSafe(2015);
Assert.AreEqual(dateTime.Minute, actual.Minute);
}
示例3: SetYearSafe_preserves_month
public void SetYearSafe_preserves_month()
{
var dateTime = new DateTime(2014, 7, 7, 22, 32, 46);
var actual = dateTime.SetYearSafe(2020);
Assert.AreEqual(dateTime.Month, actual.Month);
}
示例4: SetYearSafe_preserves_hour
public void SetYearSafe_preserves_hour()
{
var dateTime = new DateTime(2014, 7, 7, 22, 32, 46);
var actual = dateTime.SetYearSafe(2015);
Assert.AreEqual(dateTime.Hour, actual.Hour);
}
示例5: SetYearSafe_preserves_day
public void SetYearSafe_preserves_day()
{
var dateTime = new DateTime(2014, 7, 7, 22, 32, 46);
var actual = dateTime.SetYearSafe(2020);
Assert.AreEqual(dateTime.Day, actual.Day);
}
示例6: SetYearSafe_lower_bounding_applied
public void SetYearSafe_lower_bounding_applied()
{
var dateTime = new DateTime(2014, 7, 7, 22, 32, 46);
var actual = dateTime.SetYearSafe(0);
Assert.AreEqual(1, actual.Year);
}
示例7: SetYearSafe_adjusts_day_for_leapYear
public void SetYearSafe_adjusts_day_for_leapYear()
{
var dateTime = new DateTime(2016, 2, 29, 7, 22, 32, 46);
var actual = dateTime.SetYearSafe(2015);
Assert.AreEqual(28, actual.Day);
}
示例8: SetYearSafe
public void SetYearSafe()
{
var dateTime = new DateTime(2014, 7, 7, 22, 32, 46);
const int newYear = 2016;
var actual = dateTime.SetYearSafe(newYear);
Assert.AreEqual(newYear, actual.Year);
}