LoadRunner与时间有关的函数

 1.lr_save_datetime

lr_save_datetime函数将当前日期和时间,或具有指定偏移的日期和时间保存在参数中。如果达到MAX_DATETIME_LEN 个字符,结果字符串将截断。

定义:

void  lr_save_datetime(const char *format, int offset, const char *name);

例子:

lr_save_datetime ("%Y-%m-%d %H:%M:%S",DATE_NOW+TIME_NOW,"times");

上述例子中的函数将当前时间以固定格式存储在字符串变量times中。

2.   time

为C语言自带函数。根据系统时钟,time 函数返回从世界标准时间1970 年1 月1 日子夜(00:00:00)作为开始所经过的秒数。返回值存储在timeptr所给出的位置。如果timeptr为NULL,则该值不会被存储

定义:

time_t time ( time_t *timeptr );

例子:

typedef long time_t;

  time_t t;

   // Get system time and display as number and string

 lr_message ("Time in seconds since 1/1/70: %ld\n", time(&t));

 lr_message ("Formatted time and date: %s", ctime(&t));

3.   ctime

为C语言自带函数。在 Unix 下,ctime 不是线程级安全函数。所以,请使用 ctime_r。有关详细信息,请参阅平台相关文档。

定义:

char *ctime ( consttime_t *time );

例子:

typedef long time_t;

    time_t t;

    // Get system time and display as number and string

    lr_message ("Time in seconds since 1/1/70: %ld\n", time(&t));

lr_message ("Formatted time and date: %s", ctime(&t));

4.   lr_think_time

lr_think_time可以在运行期间暂停测试执行。这对于模拟思考时间非常有用,思考时间是真实用户在操作之间停下来思考的时间。单位为秒

定义:

voidlr_think_time (double time);

例子:

lr_think_time(60);     //脚本暂停运行60s

猜你喜欢

转载自www.cnblogs.com/mayyan/p/9884822.html