小编Dan*_*ott的帖子

if语句中的&&运算符

我已经制定了一个显示你的DoB的出生日期计划,它也会考虑到闰年,所以如果你输入1995年,第2个月,第29天的年份,它将会出错,因为它不是闰年.它还需要每个月有多少天,这是我需要帮助的部分.目前,它是这样的:

           if (month == 1 / && day > 31)
            {
                Console.WriteLine("January only has 31 days - Enter again");
                validDay = false;
            }
            else if (day >= 29 && !IsLeapYear(year) && month == 2)
            {
                Console.WriteLine("You were not born on a leap year or February only has 28 days - Enter again");
                validDay = false;
            }
           //And so on for each month
Run Code Online (Sandbox Code Playgroud)

所以我接着尝试了这样:

if (month == 1 || month == 3 || month == 5 || month == 7 || …
Run Code Online (Sandbox Code Playgroud)

c# if-statement logical-operators

2
推荐指数
1
解决办法
147
查看次数

获取delphi中的当前年,日和月

我基本上想要这个C#代码:

if (month > currentDate.Month || (day > currentDate.Day && month > currentDate.Month)) 
{
    age = currentDate.Year - year - 1;
}
else
{
    age = currentDate.Year - year;
}
Run Code Online (Sandbox Code Playgroud)

进入德尔福。但是我的问题是我不知道如何将当前的年,月和日作为整数获取,因此我可以进行一些计算。我已经在Google上点击了与此相关的所有结果,但没有一个对我有帮助。(确实不喜欢delphi,但是它是我们在计算机课上使用的语言)

delphi validation datetime

-4
推荐指数
1
解决办法
2万
查看次数