如何检查年份从日期改变 [英] How to check year is changed from date

查看:84
本文介绍了如何检查年份从日期改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何检查当前财政年度是否发生变化?



我尝试过的事情:



我试过这样写的

var dat = DateTime.Now()。day

var mon = DateTime.Now()。月份

if(dat == 1&& mon == 1)

{



/ /某些代码

}

how can i check that the current financial year changed ?

What I have tried:

I have tried to write like this
var dat=DateTime.Now().day
var mon=DateTime.Now().month
if(dat==1 && mon==1)
{

// Some Code
}

推荐答案

更容易使用的属性:

An easier property to use:
if (DateTime.Now.DayOfYear == 1) {
    // Some code
}


Quote:

如何检查年份是否从日期更改

How to check year is changed from date



假设您的代码已更正,您可以不测试年份是否有变化,你测试一年中的第一天。

如果当天发射超过一次那个测试失败,如果不是la那么它也会失败因任何原因在那天解雇。


Assuming your code is corrected, you do not test if the year have changed or not, you test if first day of year.
That test fail if launch more than once that day, and it also fail if not launch that day for any reason.

var lasttest;
// reload lasttest from save
var today = DateTime.Now;
if (lasttest.year < today.year)
{
	// Some Code
}
lasttest = today;
// save lasttest for later use



无论如何,此代码成功。


This code success in any case.


这篇关于如何检查年份从日期改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆