几种常用VB.NET时间函数介绍

来源:百度文库 编辑:神马文学网 时间:2024/04/29 15:01:16
    使用VB.NET进行实际编程时,会发现其中每一个函数都有自己特定的功能。比如我们这里为大家介绍的VB.NET时间函数就是其中一个功能强大的函数。

    对于VB.NET中的函数,在学习的过程中需要从各个方面去进行日常的经验积累,才能方便我们日后使用。在这里就先为大家介绍两种常用的VB.NET时间函数,方便大家参考学习,增加自己对VB.NET编程的理解。

    • VB.NET多窗体实际编写方式讲解
    • VB.NET调用存储过程详细代码编写方式解读
    • VB.NET操作CSV文件实际代码编写
    • 如何正确掌握VB.NET使用数组相关技巧
    • 全方位解读VB.NET字符串加密解密

     

    VB.NET时间函数之函数Dateadd() 

    功能:计算某个指定的时间和 

    格式: dateadd(timeinterval,number,date) 

    参数:timeinterval是时间单位(月,日..); number是时间间隔值,date是时间始点. 

    例子: 

            
    1. < %    
    2. currentDate = #8/4/99#    
    3. newDate = DateAdd
      (“m”,3,currentDate)    
    4. response.write newDate    
    5. %>   
    6. < %currentDate = 
      #12:34:45 PM#    
    7. newDate = DateAdd
      (“h”,3,currentDate)    
    8. response.write newDate    
    9. %>   

    结果: 
    11/4/99 
    3:34:45 PM 
    其中 
    “m” = ”month”; 
    “d” = ”day”; 
    如果是currentDate 格式,则, 
    “h” = ”hour”; 
    “s” = ”second”;
     
    VB.NET时间函数之函数Datediff() 

    功能:计算某量个指定的时间差 

    格式: datediff(timeinterval,date1,date2[,firstdayofweek[,firstdayofyear]]) 

    参数: timeinterval 是时间单位; date1,date2是有效的日期表达式,firstdayofweek,firstdayofyear 是任意选项. 

    例子: 

            
    1. < %fromDate = #8/4/99#    
    2. toDate = #1/1/2000#    
    3. response.write ”There 
      are ” & _    
    4. DateDiff(“d”,fromDate,
      toDate) & _    
    5. “ days to millenium 
      from 8/4/99.”    
    6. %>   

    结果:There are 150 days to millenium from 8/4/99.