vb.net显示第几周的简单介绍
VB计算一年中某一天在这一年中是第几周
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click Dim date1 As Date = txtDate.Text Dim date0 = Year(date1) "/01/01" Dim wk = DateDiff("ww", date0, date1, Microsoft.VisualBasic.FirstDayOfWeek.Monday, FirstWeekOfYear.FirstFullWeek) If (wk = 0) Then //判断周数是否为0,为0则为去年最后一周 Dim date2 = Year(date1) - 1 Dim date3 = date2 "/12/31" Dim date4 = date2 "/01/01" wk = DateDiff("ww", date4, date3, Microsoft.VisualBasic.FirstDayOfWeek.Monday, FirstWeekOfYear.FirstFullWeek) End If lblShow.Text = txtDate.Text "是" Year(date1) "第" wk "周!"End Sub
目前创新互联建站已为上千余家的企业提供了网站建设、域名、网站空间、网站托管、服务器托管、企业网站设计、仁化网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
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)
vb.net中怎么根据日期算出是周几呢?
Public Function IsRunnian(ByVal n As Integer) As Boolean
Dim res As Boolean
res = False
If n Mod 400 = 0 Then
res = True
End If
If (n Mod 100 0) And (n Mod 4 = 0) Then
res = True
End If
IsRunnian = res
End Function
Public Function Fc(ByVal td As Date) As Byte
Dim y As Integer
Dim m As Integer
Dim d As Integer
Dim yc As Integer
Dim mc As Integer
Dim dc As Integer
y = Year(td)
m = Month(td)
d = Day(td)
dc = d
If IsRunnian(y) Then
mc = Val(Mid("512503514624", m, 1))
Else
mc = Val(Mid("622503514624", m, 1))
End If
yc = ((y Mod 100) \ 4 + (y Mod 100)) Mod 7
Fc = (yc + mc + dc) Mod 7
End Function
vb编程计算某年某月某日是星期几
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), "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日")
VB6.0 要得到某一周是从哪一天开始的,哪一天结束的?
这里的“某一周”是有歧义的:
一种可能是某日期所在的周
第二种是某年的第几周。这还有歧义。因为某年的第一周,可能开始于上一年,同时这一周也是上一年的最后一周,会重复计算。我们这里假设“不管是否重复计算”
第三种是每周从星期几开始。我们这里假设“从星期一开始”。
下面分别是输出“某日期所在的周始终日期”、“某年某周始终日期”、“某年各周始终日期”的代码!
如果每周从星期日开始,将vbMonday替换为vbSunday即可。
'某日期所在的周始终日期
Private Sub Command3_Click()
Dim dt As Date
Dim wd As Integer
dt = InputBox("请输入一个日期(Date格式):", "输入日期", Date)
wd = Weekday(dt, vbMonday) '某日是星期几,周一为第一天
firstDay = DateAdd("d", -wd + 1, dt) '本周的开始日期
endDay = DateAdd("d", 7 - wd, dt) '本周的开始日期
Text1.Text = "当前日期所在的周起止日期:"
Text1.Text = Text1.Text vbNewLine
Text1.Text = Text1.Text vbNewLine "每周从星期一开始"
Text1.Text = Text1.Text vbNewLine firstDay vbTab endDay
wd = Weekday(dt, vbSunday) '某日是星期几,周日为第一天
firstDay = DateAdd("d", -wd + 1, dt) '本周的开始日期
endDay = DateAdd("d", 7 - wd, dt) '本周的开始日期
Text1.Text = Text1.Text vbNewLine
Text1.Text = Text1.Text vbNewLine "每周从星期日开始"
Text1.Text = Text1.Text vbNewLine firstDay vbTab endDay
End Sub
'某年某周始终日期
Private Sub Command4_Click()
Dim y As Integer
Dim w As Integer
Dim dt As Date
Dim wd As Integer
y = InputBox("请输入年份:", "输入年份", Year(Date))
dt = DateSerial(y, 1, 1)
w = InputBox("请输入周数:", "第几周", "")
dt = DateAdd("ww", (w - 1), dt)
wd = Weekday(dt, vbMonday) '某日是星期几,周一为第一天
firstDay = DateAdd("d", -wd + 1, dt) '本周的开始日期
endDay = DateAdd("d", 7 - wd, dt) '本周的开始日期
Text1.Text = "当前日期所在的周起止日期:"
Text1.Text = Text1.Text vbNewLine
Text1.Text = Text1.Text vbNewLine "每周从星期一开始"
Text1.Text = Text1.Text vbNewLine firstDay vbTab endDay
End Sub
'某年各周始终日期
Private Sub Command2_Click()
Dim y As Integer
Dim w As Integer
Dim dt As Date
Dim dte As Date
Dim wd As Integer
y = InputBox("请输入年份:", "输入年份", Year(Date))
dt = DateSerial(y, 1, 1)
dte = DateAdd("yyyy", 1, dt) - 1 '某年最后一天
wd = Weekday(dt, vbMonday) '某日是星期几,周一为第一天
firstDay = DateAdd("d", -wd + 1, dt) '本周的开始日期
endDay = firstDay + 6 '本周的开始日期
Text1.Text = "当前日期所在的周起止日期:"
Text1.Text = Text1.Text vbNewLine "(每周从星期一开始)"
Text1.Text = Text1.Text vbNewLine
Text1.Text = Text1.Text vbNewLine firstDay vbTab endDay
Do While endDay dte
w = w + 1
firstDay = firstDay + 7
endDay = firstDay + 6
Text1.Text = Text1.Text vbNewLine firstDay vbTab endDay
Loop
End Sub
分享名称:vb.net显示第几周的简单介绍
网页网址:http://pwwzsj.com/article/hcspsc.html