先加到9月,然后减去7天,即为8月最后一天,很好理解,如果跨年度需要判断一下,变成下个年度的1月再减即可,很简单吧
成都创新互联是专业的忻州网站建设公司,忻州接单;提供做网站、网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行忻州网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
DateTime.Today.AddMonths(1).AddDays(-DateTime.Today.Day);
变通一下这么难?我给的例子是取当天
把DateTime.Today 改成 datetimepicker1.Value 不就行了,真汗……
datetimepicker2.Value=datetimepicker1.Value.AddMonths(1).AddDays(-datetimepicker1.Value.Day);
可以使用VB.NET中的DataTime对象的AddMonths方法:
Dim d1 As Date = Now
MsgBox(d1) '显示现在的机器日期与时间
MsgBox(d1.AddMonths(2)) '显示现在的机器日期加上2个月的对应日期与时间
MsgBox(d1.AddMonths(-1)) '显示现在的机器日期减掉1个月的对应日期与时间
DataTime对象的方法很多,你可以通过在线查阅,例如:
d1.Add()
d1.AddDays()
d1.AddHours()
d1.AddMinutes()
d1.AddSeconds()
d1.AddYears()
等等!
注意:从字面意思可以理解是加,而括号里是填写对应的数值,当数值为负数,起到减的作用了。
用日期函数day()可获得当前日期,time()可获得当前系统时间.
dim CurDay as string
dim CurTime as string
curday=day()
curtime=time()
Label1.Caption = Date
就能在Label16显示当前日期
now 这个函数可以获得当前系统时间(包括年月日,小时分钟秒)
而
year()
month()
day()
等等则可以从now返回的值中分别提取年,月,日的信息
两种方式自己选用
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String
s = DateTime.Today.Year()
s = s DateTime.Today.Month()
s = s DateTime.Today.Day()
s = s DateTime.Now.Hour()
s = s DateTime.Now.Minute()
s = s DateTime.Now.Second()
MsgBox(s, vbDefaultButton1, Now())
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim s As String
s = Format(Now(), "yyyymmddhhmmss")
MsgBox(s, vbYes, Now())
End Sub
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)
Private Sub Form_Click()
Dim R As Date
R = Date '此处输入你要查看的月份中的任意一天
R = R - Day(R) + 35
R = R - Day(R)
Cls
Print R '之前输入的日期所在月份的最后一天
End Sub