gpt4 book ai didi

c# - 从函数返回日期 int 值

转载 作者:行者123 更新时间:2023-11-30 21:25:36 24 4
gpt4 key购买 nike

我尝试编写任何关于天的代码:

function xyz("13.02.2009")
{
return value= 6;
}

function xyz("12.02.2009")
{
return value= 5;
}

function xyz("14.02.2009")
{
return value= 7;
}

但是如何呢?

这个方法很好,但我需要 C# 时间特定代码(比如时间跨度...)

DayOfWeek day = DateTime.ParseExact("13.02.2008", "dd.MM.yyyy", CultureInfo.InvariantCulture).DayOfWeek;
int days = ((int)day - (int)DateTime.Now.DayOfWeek);
if (days <= 0) days += 7;
Console.Write(days);

最佳答案

请注意 DateTime.DayOfWeek 取决于您的区域设置。

关于c# - 从函数返回日期 int 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/541650/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com