本文整理汇总了C#中System.DateTime.StartOfMonth方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.StartOfMonth方法的具体用法?C# DateTime.StartOfMonth怎么用?C# DateTime.StartOfMonth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DateTime
的用法示例。
在下文中一共展示了DateTime.StartOfMonth方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartOfMonthShouldReturnExpectedResult
public void StartOfMonthShouldReturnExpectedResult()
{
var date = new DateTime( 2013, 3, 26 );
var expected = new DateTime( 2013, 3, 1 );
var actual = date.StartOfMonth();
Assert.Equal( expected.Date, actual.Date );
}
示例2: StartOfMonthWithCalendarShouldReturnExpectedResult
public void StartOfMonthWithCalendarShouldReturnExpectedResult()
{
var date = new DateTime( 2013, 3, 26 );
var calendar = new GregorianFiscalCalendar( 7 );
var expected = new DateTime( 2013, 3, 1 );
var actual = date.StartOfMonth( calendar );
Assert.Equal( expected.Date, actual.Date );
}
示例3: MsMonth
/// <summary>
/// creates a new msMonth object for the month containing the date
/// </summary>
/// <param name="date">date within the month</param>
public MsMonth(DateTime date)
{
#if NET20
StartDate = MsDateHelpers.StartOfMonth(date);
EndDate = MsDateHelpers.EndOfMonth(date);
#else
StartDate = date.StartOfMonth();
EndDate = date.EndOfMonth();
#endif
}
示例4: FromMonthRelation
protected DateTime? FromMonthRelation(string relation, int month, DateTime now, bool isUpperLimit) {
switch (relation) {
case "this": {
var start = now.Month == month ? now.StartOfMonth() : now.Month < month ? now.StartOfMonth().ChangeMonth(month) : now.StartOfMonth().AddYears(1).ChangeMonth(month);
return isUpperLimit ? start.EndOfMonth() : start;
}
case "last":
case "past":
case "previous": {
var start = now.Month > month ? now.StartOfMonth().ChangeMonth(month) : now.StartOfMonth().SubtractYears(1).ChangeMonth(month);
return isUpperLimit ? start.EndOfMonth() : start;
}
case "next": {
var start = now.Month < month ? now.StartOfMonth().ChangeMonth(month) : now.StartOfMonth().AddYears(1).ChangeMonth(month);
return isUpperLimit ? start.EndOfMonth() : start;
}
}
return null;
}
示例5: FromMonthRelation
protected DateTimeRange FromMonthRelation(string relation, int month, DateTime now) {
switch (relation) {
case "this": {
var start = now.Month == month ? now.StartOfMonth() : now.Month < month ? now.StartOfMonth().ChangeMonth(month) : now.StartOfMonth().AddYears(1).ChangeMonth(month);
return new DateTimeRange(start, start.EndOfMonth());
}
case "last":
case "past":
case "previous": {
var start = now.Month > month ? now.StartOfMonth().ChangeMonth(month) : now.StartOfMonth().SubtractYears(1).ChangeMonth(month);
return new DateTimeRange(start, start.EndOfMonth());
}
case "next": {
var start = now.Month < month ? now.StartOfMonth().ChangeMonth(month) : now.StartOfMonth().AddYears(1).ChangeMonth(month);
return new DateTimeRange(start, start.EndOfMonth());
}
}
return null;
}
示例6: StartOfMonth__The_Start_Of_A_Month_Can_Be_Obtained
public void StartOfMonth__The_Start_Of_A_Month_Can_Be_Obtained()
{
var date = new DateTime(2000, 1, 31, 4, 4, 4);
date = date.StartOfMonth();
Assert.IsTrue(date == new DateTime(2000, 1, 1));
}
示例7: StartOfMonth
public static DateTime StartOfMonth( this Calendar calendar, DateTime date )
{
Arg.NotNull( calendar, nameof( calendar ) );
Contract.Ensures( calendar.GetYear( Contract.Result<DateTime>() ) == Contract.OldValue( calendar.GetYear( date ) ) );
Contract.Ensures( calendar.GetMonth( Contract.Result<DateTime>() ) == Contract.OldValue( calendar.GetMonth( date ) ) );
return date.StartOfMonth( calendar );
}
示例8: StartOfMonth
public void StartOfMonth()
{
var start = new DateTime(2011, 1, 1);
Assert.AreEqual(start, start.StartOfMonth());
Assert.AreEqual(start, start.AddDays(2).StartOfMonth());
Assert.AreEqual(start, start.AddDays(28).StartOfMonth());
Assert.AreEqual(start, new DateTime(2011, 1, 31).StartOfMonth());
Assert.AreNotEqual(start, start.AddMonths(1).StartOfMonth());
Assert.AreNotEqual(start, start.AddMonths(-1).StartOfMonth());
}