Equivalent of WeekDay Function of VB6 in C#(C#中VB6的WeekDay函数的等价物)
问题描述
在 VB6 代码中,我有以下内容:
In VB6 code, I have the following:
dim I as Long
I = Weekday(Now, vbFriday)
我想要 C# 中的等价物.有人可以帮忙吗?
I want the equivalent in C#. Can any one help?
推荐答案
public static int Weekday(DateTime dt, DayOfWeek startOfWeek)
{
return (dt.DayOfWeek - startOfWeek + 7) % 7;
}
这可以使用:
DateTime dt = DateTime.Now;
Console.WriteLine(Weekday(dt, DayOfWeek.Friday));
以上输出:
4
因为星期二是星期五之后的 4 天.
as Tuesday is 4 days after Friday.
这篇关于C#中VB6的WeekDay函数的等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!