您的位置:程序门 -> .net技术 -> vb.net



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


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


每天都判断当前时间,如果是14:30以前就把日期变量减一天,该怎么做[已结贴,结贴人:ahking]
发表于:2007-03-08 11:16:08 楼主
每天都判断当前时间,如果是14:30以前就把日期变量减一天,该怎么做  
假设vardate为日期变量,当前时间为11:15,则返回vardate的上一天的日期,vardate日期格式为yyyy-mm-dd
发表于:2007-03-08 11:23:061楼 得分:5
datetime   now   =   datetime.now
if   (now.hour <14   ¦ ¦   now.hour==14   &&   now.minute <30)
{
        string   vardate   =   now.adddays(-1).tostring( "yyyy-mm-dd ");
}
发表于:2007-03-08 11:24:572楼 得分:0
sorry,没注意是vb
dim   vardate   as   string
dim   now   as   date   =   now
if   now.hour <14   or   now.hour==14   and   now.minute <30   then
        vardate   =   now.adddays(-1).tostring( "yyyy-mm-dd ")
end   if
发表于:2007-03-08 11:26:123楼 得分:0
dim   now   as   date   =   now
if   now.hour <14   or   now.hour==14   and   now.minute <30   then
        vardate   =   date.parse(vardate).adddays(-1).tostring( "yyyy-mm-dd ")
end   if
发表于:2007-03-08 11:35:224楼 得分:0
if   now.hour <14   or   now.hour==14   and   now.minute <30   then出错,提示需要表达式!
发表于:2007-03-08 11:37:065楼 得分:0
加个timer,每1秒检查一次:)
发表于:2007-03-08 11:39:166楼 得分:5
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
发表于:2007-03-08 11:44:257楼 得分:5
==vb里是=
从c#反过来的,忙中出错
发表于:2007-03-08 11:50:598楼 得分:5
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


快速检索

最新资讯
热门点击