robotframework - 使用Robot框架评估后如何使用0获取月份格式
问题描述
我尝试在评估月份后获得像“06/19”这样的月份和年份格式,但我得到的只是“6/19”。
Month and year
${currentYear}= Get Current Date result_format=%y
${currentDate}= Get Current Date
${datetime} = Convert Date ${currentDate} datetime
${getMonth}= evaluate ${datetime.month} - 1
log to console ${getMonth}/${currentYear}
我已经通过创建变量 @{MONTHSNO} ${EMPTY} 01 02 03 04 05 06 07 08 09 10 11 12 尝试了另一种方法并返回 ${MONTHSNO}[${getMonth}]/${currentYear} 我得到了 06/19但我不确定机器人是否有另一种方法可以将月份转换为“06”,而无需制作像这样的变量。
解决方案
当您运行 Evaluate 命令时,您正在运行 python 命令。因此,让我们看一下 datetime 文档:
https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior
他们最后有这一部分说图书馆时间很有用。所以我建议你使用这个命令以 0X 格式返回月份:
${getMonth}= evaluate time.strftime("%m")
这只是把 07 还给我(因为现在是七月)
推荐阅读
- html - 在 HTML 中使用 RTSP 流
- r - 如何将效果大小添加到 t 检验的 ggplot 条形图?(例如,Cohen 的 d 或 Hedges 的 g)
- python - 在不同条件下迭代时遇到问题
- node.js - 通过 REST API 上传/编码文件
- mongodb - 我们可以在 Jest 中结合两个预设 MongoDB 和 puppeteer 吗?
- javascript - 显示存储在 mongoDB 中的日期的星期几
- java - Java FXML - 尝试加载新场景时出现空指针异常
- python - 连接表(1:多表关系)的正确 SQLAlchemy ORM 结构是什么?
- javascript - Django 在模板标签中使用变量
- python - Aiogram python InlineKeyboard