如何将Ubuntu Jenkins代理的时间格式调整为与Debian一致?
可以调整Ubuntu的时间格式与Debian一致,分系统时间和Cypress日志两部分处理:
一、调整系统时间格式
Debian的系统时间格式(Tue 21 Feb 2023 09:21:45 PM CET)由locale时间区域设置决定,Ubuntu默认格式不同是因为LC_TIME参数值不一致。
操作步骤:
确认Debian的LC_TIME值:在Debian代理上执行命令,获取当前生效的时间区域配置:
locale | grep LC_TIME通常输出类似
LC_TIME="en_GB.UTF-8"(欧洲地区locale会采用日在前、月在后的格式)。在Ubuntu上安装对应locale(若未安装):
sudo locale-gen en_GB.UTF-8设置Ubuntu的LC_TIME为Debian同款:
- 临时生效(仅当前会话):
执行export LC_TIME=en_GB.UTF-8date命令验证格式是否变为Debian样式。 - 永久生效(系统全局):
重启Ubuntu代理或重新登录后,系统时间格式将与Debian一致。sudo update-locale LC_TIME=en_GB.UTF-8
- 临时生效(仅当前会话):
二、调整Cypress日志时间格式
Cypress日志的时间格式差异(有无at、替换为逗号)同样依赖系统locale设置,完成上述系统时间调整后,Cypress会自动继承新的locale,日志格式通常会同步变为Debian样式。
如果调整系统locale后仍未生效,可通过Cypress配置文件手动指定时间格式:
在cypress.config.js中添加自定义日志格式化逻辑:
const { defineConfig } = require("cypress"); module.exports = defineConfig({ e2e: { setupNodeEvents(on, config) { // 覆盖默认日志的时间格式 on('log:added', (options) => { if (options.displayName === 'log') { const date = new Date(options.timestamp); // 生成Debian风格的时间字符串 const formattedTime = new Intl.DateTimeFormat('en-GB', { year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true, timeZoneName: 'short' }).format(date).replace(' at ', ', '); options.message = `${formattedTime} ${options.message}`; } }); }, }, });
内容的提问来源于stack exchange,提问作者IFThenElse
相关产品推荐
相关产品推荐

