您的位置:程序门 -> vb -> 基础类



vb 时间大问题


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


vb 时间大问题[已结贴,结贴人:twtyypeuxk]
发表于:2007-01-24 10:56:40 楼主
vb   如果得到时间格式是这样的呢?
例:1169606370  
用php中用time来得到的时间一样,但在vb中如果实理呢?
发表于:2007-01-24 11:12:451楼 得分:0
yyyy-mm-dd

hh:mm:ss

vb时间只支持到秒,再小的单位不支持
发表于:2007-01-24 11:25:212楼 得分:0
我那样格式也是只到秒而以啊
发表于:2007-01-24 11:47:283楼 得分:0
dim   stime   as   string

stime=str(time)
发表于:2007-01-24 13:02:414楼 得分:0
?   clng(#9999-12-31   23:59:59#)
结果:   2958466  
精确到秒的时间值

?   clng(now)
  39107  
发表于:2007-01-24 13:06:025楼 得分:0
?   clng(#9999-12-31   23:59:59#)
结果:   2958466  

?   clng(now)
39107
发表于:2007-01-24 17:22:476楼 得分:0
以上的方法都不行
发表于:2007-01-24 17:48:227楼 得分:0
你先告诉我们,1169606370代表哪个时间?,也许有换算方法
发表于:2007-01-25 09:30:378楼 得分:0
1169606370代表的是什么时间?
发表于:2007-01-25 10:30:119楼 得分:0
这两个“时间”,有本质的差别

?   cdbl(cdate( "1900-01-01   0:0:1 "))     ,   cdbl(cdate( "1800-01-01   0:0:1 "))

2.00001157407407         -36522.0000115741  


可见,vb的时间是从   1900-01-01   开始的,所以,比较小,秒是在小数点后面体现的。

php的那个时间,又是从什么时候开始的?  
   

发表于:2007-01-25 11:44:0510楼 得分:0
1169606370   这个应该是utc时间,即从1970-01-01   00:00:00开始到现在的秒数
发表于:2007-01-25 12:57:2611楼 得分:20
正好前几天遇到这个问题,用c编写了一个转换utc的程序,翻译成vb:

private   function   utctodatetime(lngseconds   as   long)   as   string
        dim   nyear   as   long,   nmonth   as   long,   nday   as   long,   nhour   as   long,   nmin   as   long,   nsec   as   long

        ' ' '取得年份
        nyear   =   1970
        do   while   (lngseconds   > =   getyearseconds(nyear))
                lngseconds   =   lngseconds   -   getyearseconds(nyear)
                nyear   =   nyear   +   1
        loop
        ' ' '取得月份
        nmonth   =   1
        do   while   (lngseconds   > =   getmonthseconds(nyear,   nmonth))
                lngseconds   =   lngseconds   -   getmonthseconds(nyear,   nmonth)
                nmonth   =   nmonth   +   1
        loop

        nday   =   lngseconds   \   (3600#   *   24)   +   1
        lngseconds   =   lngseconds   mod   (3600#   *   24)
       
        nhour   =   lngseconds   \   (3600#)
        lngseconds   =   lngseconds   mod   3600#
       
        nmin   =   lngseconds   \   60#
        lngseconds   =   lngseconds   mod   60
       
        nsec   =   lngseconds
       
       
        utctodatetime   =   cstr(nyear)   &   "- "   &   cstr(nmonth)   &   "- "   &   cstr(nday)   &   "   "   &   cstr(nhour)   &   ": "   &   cstr(nmin)   &   ": "   &   cstr(nsec)
        utctodatetime   =   format(utctodatetime,   "yyyy-mm-dd   hh:nn:ss ")
end   function

' ' '将现在时刻转化成自1970-01-01   00:00:00经过的秒数
private   function   nowtoutc(ttime   as   date)   as   long
        dim   nyear   as   long,   nmonth   as   long
        dim   lngsenconds   as   long
       
        lngsenconds   =   0
        for   nyear   =   1970   to   year(ttime)   -   1
                lngsenconds   =   lngsenconds   +   getyearseconds(nyear)
        next
       
        for   nmonth   =   1   to   month(ttime)   -   1
                lngsenconds   =   lngsenconds   +   getmonthseconds(nyear,   nmonth)
        next
       
        lngsenconds   =   lngsenconds   +   3600#   *   24   *   (day(ttime)   -   1)
        lngsenconds   =   lngsenconds   +   3600#   *   hour(ttime)
        lngsenconds   =   lngsenconds   +   60   *   minute(ttime)
        lngsenconds   =   lngsenconds   +   second(ttime)

        nowtoutc   =   lngsenconds
end   function


private   function   getyearseconds(year   as   long)   as   long
        if   year   mod   400   =   0   or   (year   mod   4   =   0   and   year   mod   100   <>   0)   then
                getyearseconds   =   366#   *   3600#   *   24#
        else
                getyearseconds   =   365#   *   3600#   *   24#
        end   if
end   function

private   function   getmonthseconds(year   as   long,   month   as   long)   as   long
        select   case   month
                case   1,   3,   5,   7,   8,   10,   12
                        getmonthseconds   =   3600#   *   24   *   31
                case   4,   6,   9,   11
                        getmonthseconds   =   3600#   *   24   *   30
                case   2
                        if   year   mod   400   =   0   or   (year   mod   4   =   0   and   year   mod   100   <>   0)   then
                                getmonthseconds   =   3600#   *   24   *   29
                        else
                                getmonthseconds   =   3600#   *   24   *   28
                        end   if
        end   select
end   function

private   sub   command1_click()
        dim   i   as   long
        dim   t   as   date
        t   =   now
        i   =   nowtoutc(t)
        debug.print   "now:   ";   t
        debug.print   "utc:   ";   cstr(i)
        debug.print   "time: ";   utctodatetime(i)
end   sub

运行结果:
now:   2007-1-25   12:55:19  
utc:   1169729719
time:2007-01-25   12:55:19
发表于:2007-01-25 13:17:3412楼 得分:0
我记得vb的date是1900-1-1   0:0:0以来的天数,double型,整数部分表示天数,小数部分表示时间


快速检索

最新资讯
热门点击