我想计算两个日期之间的差异.这就是我目前使用的:
int currentyear = DateTime.Now.Year;
DateTime now = DateTime.Now;
DateTime then = new DateTime(currentyear, 12, 26);
TimeSpan diff = now - then;
int days = diff.Days;
label1.Text = days.ToString() + " Days Until Christmas";
Run Code Online (Sandbox Code Playgroud)
一切正常,除了休息一天.我假设这是因为它不计算一整天不到24小时.有没有办法让它这样做?谢谢.
我想在我的网络应用程序中计算年份和月份.
在我的代码中,我有一年201604.我想把这个月减去3,所以它应该是201601.我得到了这部分工作但现在如果我想再次减去另外3个monyths 201601,结果应该是201511.我不知道该怎么做这部分.帮助将不胜感激
码
decimal str = "201604";
decimal year= (decimal) Calculations.ParseStringToDecimal(str.SubString(0,4), 0);
decimal month = (decimal) Calculations.ParseStringToDecimal(str.SubString(4,2), 0);
newMonth = month - 3;
string newDate = year + month
//Result: 201601.
//I want to subtract 201601 again, then the result should be 201511.
Run Code Online (Sandbox Code Playgroud)