本文整理汇总了C#中System.Date类的典型用法代码示例。如果您正苦于以下问题:C# Date类的具体用法?C# Date怎么用?C# Date使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Date类属于System命名空间,在下文中一共展示了Date类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Comparison
public void Comparison()
{
var firstDate = new Date(2011, 1, 1);
var sameAsFirstDate = new Date(2011, 1, 1);
var laterDate = new Date(2011, 1, 2);
Expect(firstDate < laterDate);
Expect(laterDate < firstDate, Is.False);
Expect(firstDate > laterDate, Is.False);
Expect(laterDate > firstDate);
Expect(firstDate <= laterDate);
Expect(laterDate <= firstDate, Is.False);
Expect(firstDate >= laterDate, Is.False);
Expect(laterDate >= firstDate);
Expect(firstDate <= sameAsFirstDate);
Expect(firstDate >= sameAsFirstDate);
Expect(firstDate < sameAsFirstDate, Is.False);
Expect(firstDate > sameAsFirstDate, Is.False);
Expect(firstDate, Is.EqualTo(sameAsFirstDate));
Expect(firstDate.Equals(sameAsFirstDate));
}
示例2: GetMonthlyPrintNumber
public static int GetMonthlyPrintNumber(Date date, int refNumber, Date refDate, Month noPrintMonths, Dictionary<int, int> noPrintDates, Dictionary<int, int> noPrintNumbers)
{
int no = refNumber;
Date date2 = refDate;
while (date > date2)
{
date2 = date2.AddMonths(1);
Month month = zdate.GetMonth(date2.Month);
if ((noPrintMonths & month) != month && !noPrintDates.ContainsKey(date2.AbsoluteDay))
{
do
{
no++;
} while (noPrintNumbers.ContainsKey(no));
}
}
while (date < date2)
{
Month month = zdate.GetMonth(date2.Month);
if ((noPrintMonths & month) != month && !noPrintDates.ContainsKey(date2.AbsoluteDay))
{
do
{
no--;
} while (noPrintNumbers.ContainsKey(no));
}
date2 = date2.AddMonths(-1);
}
return no;
}
示例3: Construction
public Construction(BuildingType type, Settlement location, Date today)
{
_type = type;
_location = location;
_startDate = today;
//_resourceRequirements = _type.RequirementsFor(location);
}
示例4: Contains
/// <summary>
/// Contains 目标时刻是否在时间范围内
/// </summary>
public bool Contains(Date target)
{
bool bStart = this._start.CompareTo(target) <= 0;
bool bEnd = this._end.CompareTo(target) >= 0;
return bStart && bEnd;
}
示例5: Main
static void Main(string[] args)
{
Date aDate = new Date();
Date anotherDate = new Date(2003, 11, 5);
Console.WriteLine("aDate:\n" + aDate);
Console.WriteLine("anotherDate:\n" + anotherDate);
}
示例6: EmbeddingOfInstanceOfCustomValueTypeWithFieldsIsCorrect
public virtual void EmbeddingOfInstanceOfCustomValueTypeWithFieldsIsCorrect()
{
// Arrange
var date = new Date(2015, 12, 29);
const string updateCode = "date.Day += 2;";
const string input1 = "date.Year";
const int targetOutput1 = 2015;
const string input2 = "date.Month";
const int targetOutput2 = 12;
const string input3 = "date.Day";
const int targetOutput3 = 31;
// Act
int output1;
int output2;
int output3;
using (var jsEngine = CreateJsEngine())
{
jsEngine.EmbedHostObject("date", date);
jsEngine.Execute(updateCode);
output1 = jsEngine.Evaluate<int>(input1);
output2 = jsEngine.Evaluate<int>(input2);
output3 = jsEngine.Evaluate<int>(input3);
}
// Assert
Assert.AreEqual(targetOutput1, output1);
Assert.AreEqual(targetOutput2, output2);
Assert.AreEqual(targetOutput3, output3);
}
示例7: ctor_DateTime_whenLocalTime
public void ctor_DateTime_whenLocalTime()
{
Date expected = "2012-03-26";
var actual = new Date(new DateTime(2012, 03, 25, 2, 1, 0, DateTimeKind.Local)).ToDateTime().AddDays(1).ToDate();
Assert.Equal(expected, actual);
}
示例8: CalculateFee
/// <summary>
/// If the book is returned on or before the expected return date, no fine will be charged, in other words fine is 0.
/// If the book is returned in the same month as the expected return date, Fine = 15 Hackos × Number of late days
/// If the book is not returned in the same month but in the same year as the expected return date, Fine = 500 Hackos × Number of late months
/// If the book is not returned in the same year, the fine is fixed at 10000 Hackos.
/// </summary>
static int CalculateFee(Date returnDate, Date expectedDate)
{
if (returnDate.year > expectedDate.year) { return 10000; }
else if ((returnDate.year == expectedDate.year) && returnDate.month > expectedDate.month) { return (returnDate.month - expectedDate.month) * 500; }
else if ((returnDate.year == expectedDate.year && returnDate.month == expectedDate.month) && returnDate.day > expectedDate.day) { return (returnDate.day - expectedDate.day) * 15; }
else { return 0; } // returned early
}
示例9: CanConstructFromDateTime
public void CanConstructFromDateTime()
{
Date d1 = new Date(new DateTime(2001, 2, 3, 4, 5, 6, 7).AddTicks(8));
Date d2 = new Date(2001, 2, 3);
Assert.AreEqual(d1, d2);
Assert.IsTrue(d1.Equals(d2));
}
示例10: AddMinutes_2280_AreEqual
public void AddMinutes_2280_AreEqual()
{
var act = TestStruct.AddMinutes(2 * 24 * 60);
var exp = new Date(1970, 02, 16);
Assert.AreEqual(exp, act);
}
示例11: AddMonths_12_AreEqual
public void AddMonths_12_AreEqual()
{
var act = TestStruct.AddMonths(12);
var exp = new Date(1971, 02, 14);
Assert.AreEqual(exp, act);
}
示例12: AddMilliseconds_Arround3Days_AreEqual
public void AddMilliseconds_Arround3Days_AreEqual()
{
var act = TestStruct.AddMilliseconds(3 * 24 * 60 * 60 * 1003);
var exp = new Date(1970, 02, 17);
Assert.AreEqual(exp, act);
}
示例13: AddHours_41_AreEqual
public void AddHours_41_AreEqual()
{
var act = TestStruct.AddHours(41);
var exp = new Date(1970, 02, 15);
Assert.AreEqual(exp, act);
}
示例14: Equals_ConstructorDateWithTime_DoesNotCompareTime
public void Equals_ConstructorDateWithTime_DoesNotCompareTime()
{
var dayWithTime = new Date(new DateTime(2011, 1, 1, 1, 0, 0));
var sameDayWithOutTime = new Date(new DateTime(2011, 1, 1));
Expect(dayWithTime, Is.EqualTo(sameDayWithOutTime));
}
示例15: ViewMoverKenBurnsStyle
public ViewMoverKenBurnsStyle(CameraParameters from, CameraParameters to, double time, Date fromDateTime, Date toDateTime, InterpolationType type)
{
InterpolationType = type;
if (Math.Abs(from.Lng - to.Lng) > 180)
{
if (from.Lng > to.Lng)
{
from.Lng -= 360;
}
else
{
from.Lng += 360;
}
}
this.fromDateTime = fromDateTime;
this.toDateTime = toDateTime;
dateTimeSpan = toDateTime - fromDateTime;
this.from = from.Copy();
this.to = to.Copy();
fromTime = Date.Now;
toTargetTime = time;
}