VB.NET中的DateTime问题 [英] DateTime question in VB.NET

查看:110
本文介绍了VB.NET中的DateTime问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我需要通过编程方式找到星期一的日期。

Ok, so I need to find the date of Monday this week programmatically.

例如,本周星期一是在9日,所以我需要的日期是:09/11/2009

For example, for this week Monday was on the 9th, so the date I need is: 09/11/2009

当我们滚动到下周,它需要计算:16/11/2009

And when we roll over to next week it needs to calculate: 16/11/2009

我已经尝试这样做了,但是看不到如何做算术,谢谢。

I have tried doing this myself but I can't see how to do the arithmetic, thank you.

推荐答案

C#:

date.AddDays(1 - (date.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)date.DayOfWeek));

VB.NET:

date.AddDays(1 - IIf((date.DayOfWeek = DayOfWeek.Sunday), 7, date.DayOfWeek))

这篇关于VB.NET中的DateTime问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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