十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
Dim ThisDay As String = Format(Now, "yyyy-MM-dd") '获得当前日期字符串
目前创新互联公司已为上1000+的企业提供了网站建设、域名、网络空间、网站运营、企业网站设计、隆尧网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
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)
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)
这个非常简单的.
用时间函数,然后用文字转下.就行了.
我现在用的是.NET,不太清楚VB6.0是不是了.
你先用 日期里的Month 把一个时间中的月份取出来 .
再用Format转化下文本格式, 比如用的月份是 mon 那么就是: Format(mon,"00")
这样就行了. "00" 表示的是以两位数字显示,没到两位的以0补.
如果是在EXCEL宏里,那就直接给你写了吧:
Dim Mon1 As String
Dim Mon2 As String
Mon1 = VBA.Month(VBA.Now)
Mon2 = Format(Mon1, "00")
这里的Mon2 就是 你的那个月份.
用日期函数day()可获得当前日期,time()可获得当前系统时间.
dim CurDay as string
dim CurTime as string
curday=day()
curtime=time()
Label1.Caption = Date
就能在Label16显示当前日期
now 这个函数可以获得当前系统时间(包括年月日,小时分钟秒)
而
year()
month()
day()
等等则可以从now返回的值中分别提取年,月,日的信息
不是 有 函数嘛?
now() 就是 吧
取得 后 再 分离出你所需的,分别赋值 就行了,当然 还是 有 函数的
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Short = Date.Now.Month
Dim b As Short = Date.Now.Day
MessageBox.Show(a)
MessageBox.Show(b)
End Sub
上面是获取月份以及天数
'======================
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Short = Date.Now.Month
Dim b As Short = Date.Now.Day
Dim c, d As String
If a 0 AndAlso a 10 Then
c = "1位数"
Else
c = "2位数"
End If
If b 0 AndAlso b 10 Then
d = "1位数"
Else
d = "2位数"
End If
MessageBox.Show(c)
MessageBox.Show(d)
End Sub
这个是获取位数的