10.RobotFramework: 获取当前时间戳

robot中先导入DateTime库

对时间操作的datetime库常用关键字:

1,获取当前时间戳

#获取当前时间
${time} get current date
#转化为原始时间戳
${time_stamp} convert date ${time} epoch
#转化为毫秒级时间戳
${time_stamp2} evaluate int(round(${time_stamp}*1000))

 

20200622 10:54:43.846 : INFO : ${time} = 2020-06-22 10:54:43.846
20200622 10:54:43.854 : INFO : ${time_stamp} = 1592794483.846
20200622 10:54:43.856 : INFO : ${time_stamp2} = 1592794483846

 

${Year}    Get Current Date    result_format=%Y

${Month}    Get Current Date    result_format=%m

${currentMonth}    Get Current Date    result_format=%Y%m

 

时间格式转化:

${usageUpdateTime}    convert date    ${update_time}    exclude_millis=yes    result_format=%Y%m%d%H%M%S

20200924 11:07:16.593 : INFO : ${update_time} = 2019-09-04 11:45:58
20200924 11:07:16.598 : INFO : ${usageUpdateTime} = 20190904114558

 

获取%Y%m%d%H%M%S的时间格式

${Date} Get Current Date result_format=%Y%m%d%H%M%S

获取到的的时间基础上+1秒
${Date1} add time to date ${Date} 1 seconds result_format=%Y%m%d%H%M%S

20201016 13:58:23.853 : INFO : ${Date} = 20201016135824
20201016 13:58:23.854 : INFO : ${Date1} = 20201016135825

 

2,对固定日期进行操作,增加或减去单位时间或者时间段

 

3、对时间格式转化,获取时间戳

 

4、从完整时间中取指定年月日等

 

posted on 2020-06-22 11:29  走路带风的帅界扛把子  阅读(3327)  评论(0编辑  收藏  举报