利用format函数对时间变量进行计算

来源:互联网 发布:预算软件破解 编辑:程序博客网 时间:2024/06/13 03:40

    首先让我们先介绍一下format函数

    format函数是CString类的一个成员函数,它通过格式操作使任意(大家注意这个“任意”,证明这个函数非常强大)类型的数据转换成一个字符串。

    格式:function Format(const Format: string; const Args: array of const): string; overload

    其中:Format参数是一个格式字符串,用于格式化Args里面的值的。Args是一个变量数组,即它里面可以有多个参数,而且每个参数可以不同。

    那么,等我们真正要用到的时候,我们只需掌握它的一些示例用法即可,如我们今天要用到的,利用它来进行时间变量的计算。

    Dim upTime As Date
    Dim downtime As Date

    upTime = Text8.Text
    downtime = Text10.Text
    onLineTime = Format(downtime + upTime, "HH:MM:SS")

    即可实现对时间变量的计算

    相似的示例如:

  Dim MyTime, MyDate, MyStr
  MyTime = #17:04:23#
  MyDate = #January 27, 1993#
  ' 以系统设置的长时间格式返回当前系统时间。
  MyStr = Format(Time, "Long Time")
  ' 以系统设置的长日期格式返回当前系统日期。
  MyStr = Format(Date, "Long Date")
  MyStr = Format(MyTime, "h:m:s") ' 返回 "17:4:23"。
  MyStr = Format(MyTime, "hh:mm:ss AMPM") ' 返回 "05:04:23 PM"。
  MyStr = Format(MyDate, "dddd, mmm d yyyy") ' 返回 "Wednesday, Jan 27 1993"。






0 0
原创粉丝点击