vb下有没有直接把1970/1/1来的秒数转换成日期时间的方法?

解决方案 »

  1.   

    DateAdd 函数
          
    返回包含一个日期的 Variant (Date),这一日期还加上了一段时间间隔。语法DateAdd(interval, number, date)DateAdd 函数语法中有下列命名参数:部分 描述 
    interval 必要。字符串表达式,是所要加上去的时间间隔。 
    number 必要。数值表达式,是要加上的时间间隔的数目。其数值可以为正数(得到未来的日期),也可以为负数(得到过去的日期)。 
    date 必要。Variant (Date) 或表示日期的文字,这一日期还加上了时间间隔。 
    设置interval 参数具有以下设定值:设置 描述 
    yyyy 年 
    q 季 
    m 月 
    y 一年的日数 
    d 日 
    w 一周的日数 
    ww 周 
    h 时 
    n 分钟 
    s 秒 
    说明可以使用 DateAdd 函数对日期加上或减去指定的时间间隔。例如,可以用 DateAdd 来计算距今天为三十天的日期;或者计算距现在为 45 分钟的时间。为了对 date 加上“日”,可以使用“一年的日数” (“y”),“日” (”d”) 或“一周的日数” (”w”)。DateAdd 函数将不返回有效日期。在以下实例中将 1 月31 日加上一个月:
      

  2.   

    上边那个方法不行的,谁还有办法
    我自己写的函数有点不准,帮我看看?
      Dim lastsec
            Dim totalsec
            Dim yearsec
            Dim monthsec
            Dim daysec
            Dim hoursec
            Dim totalyear
            Dim totalmonth
            Dim totalday
            Dim totalhour
            Dim curryear
            Dim d
            yearsec = 365 * 24 * 3600
            monthsec = 30.42 * 24 * 3600
            daysec = 24 * 3600
            hoursec = 3600
            totalsec = 1048268556 - 691200(减去闰年)
            d = TimeSerial(0, 0, totalsec)
            totalyear = Int(totalsec / yearsec)
            lastsec = totalsec Mod yearsec
            totalmonth = Int(lastsec / monthsec)
            lastsec = lastsec Mod monthsec
            totalday = Int(lastsec / daysec)
            lastsec = lastsec Mod daysec
            totalhour = Int(lastsec / hoursec)
    然后时间就= 1970& totalyear &"-"&1 & totalmonth &"-" &1 & totalday这样的时间是有误差的,大家帮忙看看