VB内置的Weekday函数就可以返回星期.
创新互联专注于淇滨网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供淇滨营销型网站建设,淇滨网站制作、淇滨网页设计、淇滨网站官网定制、成都小程序开发服务,打造淇滨网络公司原创品牌,更为您提供淇滨网站排名全网营销落地服务。
Weekday(date[, firstdayofweek])
-- date: 必要; Date类型; 要求的日期
-- firstdayofweek: 可选; vbDayOfWeek类型; 定义每周第一天(默认为星期天)
Weekday返回一个Integer, 代表每周第几天.
============================================
WeekdayName(weekday[, abbreviate][, firstdayofweek])
-- weekday: 必要; Long类型; 每周第几天
-- abbreviate: 可选; Boolean类型; 表示星期的名称是否被缩写(默认为False)
-- firstdayofweek: 可选; vbDayOfWeek类型; 定义每周第一天(默认为星期天)
WeekdayName返回一个String, 如"星期一", 但根据不同的系统, 也会返回如"Monday".
============================================
你也可以不用WeekdayName自己得到星期名
Choose(Weekday(#8/8/2008#, vbMonday), "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日")
C#
string [] Day=new string []{"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
Console.WriteLine(Day[Convert.ToInt16(DateTime.Now.DayOfWeek)]);
相信VB.net的你,应该懂的。
Dim ThisDay As String = Format(Now, "yyyy-MM-dd") '获得当前日期字符串
Dim ThisDateTime As DateTime = Convert.ToDateTime(ThisDay) '当前日期转换成DateTime
Dim ThisWeekDay As Integer = ThisDateTime.DayOfWeek '获得当前日期是星期几
Dim differadd As Integer = 1 - ThisWeekDay '相差的天数(星期1与当前星期几相差的天数)
Dim MyAdd As New TimeSpan(differadd, 0, 0, 0)
Dim MyYear As Integer = Format(Now, "yyyy") '获取当前日期的年份
Dim MyMonth As Integer = Format(Now, "MM") '获取当前日期的月份
Dim MyDay As Integer = Format(Now, "dd") '获取当前日期是几号
Dim MyToday As DateTime = New DateTime(MyYear, MyMonth, MyDay)
Dim Yourday As DateTime = MyToday.Add(MyAdd)
MsgBox("本周星期一的日期是:" Yourday)