VB內(nèi)置的Weekday函數(shù)就可以返回星期.
創(chuàng)新互聯(lián)專注于淇濱網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供淇濱營銷型網(wǎng)站建設(shè),淇濱網(wǎng)站制作、淇濱網(wǎng)頁設(shè)計、淇濱網(wǎng)站官網(wǎng)定制、成都小程序開發(fā)服務(wù),打造淇濱網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供淇濱網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
Weekday(date[, firstdayofweek])
-- date: 必要; Date類型; 要求的日期
-- firstdayofweek: 可選; vbDayOfWeek類型; 定義每周第一天(默認(rèn)為星期天)
Weekday返回一個Integer, 代表每周第幾天.
============================================
WeekdayName(weekday[, abbreviate][, firstdayofweek])
-- weekday: 必要; Long類型; 每周第幾天
-- abbreviate: 可選; Boolean類型; 表示星期的名稱是否被縮寫(默認(rèn)為False)
-- firstdayofweek: 可選; vbDayOfWeek類型; 定義每周第一天(默認(rèn)為星期天)
WeekdayName返回一個String, 如"星期一", 但根據(jù)不同的系統(tǒng), 也會返回如"Monday".
============================================
你也可以不用WeekdayName自己得到星期名
Choose(Weekday(#8/8/2008#, vbMonday), "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日")
C#
string [] Day=new string []{"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
Console.WriteLine(Day[Convert.ToInt16(DateTime.Now.DayOfWeek)]);
相信VB.net的你,應(yīng)該懂的。
Dim ThisDay As String = Format(Now, "yyyy-MM-dd") '獲得當(dāng)前日期字符串
Dim ThisDateTime As DateTime = Convert.ToDateTime(ThisDay) '當(dāng)前日期轉(zhuǎn)換成DateTime
Dim ThisWeekDay As Integer = ThisDateTime.DayOfWeek '獲得當(dāng)前日期是星期幾
Dim differadd As Integer = 1 - ThisWeekDay '相差的天數(shù)(星期1與當(dāng)前星期幾相差的天數(shù))
Dim MyAdd As New TimeSpan(differadd, 0, 0, 0)
Dim MyYear As Integer = Format(Now, "yyyy") '獲取當(dāng)前日期的年份
Dim MyMonth As Integer = Format(Now, "MM") '獲取當(dāng)前日期的月份
Dim MyDay As Integer = Format(Now, "dd") '獲取當(dāng)前日期是幾號
Dim MyToday As DateTime = New DateTime(MyYear, MyMonth, MyDay)
Dim Yourday As DateTime = MyToday.Add(MyAdd)
MsgBox("本周星期一的日期是:" Yourday)