首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

每天都判断当前时间,如果是14:30以前就把日期变量减一天,该如何做

2012-02-03 
每天都判断当前时间,如果是14:30以前就把日期变量减一天,该怎么做每天都判断当前时间,如果是14:30以前就把

每天都判断当前时间,如果是14:30以前就把日期变量减一天,该怎么做
每天都判断当前时间,如果是14:30以前就把日期变量减一天,该怎么做  
假设vardate为日期变量,当前时间为11:15,则返回vardate的上一天的日期,vardate日期格式为yyyy-mm-dd

[解决办法]
DateTime now = DateTime.Now
if (now.Hour <14 || now.Hour==14 && now.Minute <30)
{
string vardate = now.AddDays(-1).ToString( "yyyy-MM-dd ");
}
[解决办法]
Public Class Form1

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim vardate As Date = Now
If Date.Compare(vardate.ToShortTimeString, #2:30:00 PM#) Then
vardate = vardate.AddDays(-1)
MsgBox(vardate.ToShortDateString)
Else
MsgBox(vardate.ToShortDateString)
End If
End Sub
End Class
[解决办法]
==VB里是=
从C#反过来的,忙中出错
[解决办法]
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MsgBox(ChkDate(Now, "14:30 ").ToString( "yyyy-MM-dd "))
End Sub

Public Function ChkDate(ByVal NowDate As Date, ByVal TimeChkPoint As String) As Date
Dim iTimeSpan As TimeSpan
iTimeSpan = NowDate.Subtract(Date.Parse(TimeChkPoint))
If iTimeSpan.TotalSeconds < 0 Then
Return (NowDate.AddDays(-1))
Else
Return NowDate
End If
End Function
End Class

热点排行