You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Ubuntu Jenkins代理的时间格式调整为与Debian一致?

可以调整Ubuntu的时间格式与Debian一致,分系统时间和Cypress日志两部分处理:

一、调整系统时间格式

Debian的系统时间格式(Tue 21 Feb 2023 09:21:45 PM CET)由locale时间区域设置决定,Ubuntu默认格式不同是因为LC_TIME参数值不一致。

操作步骤:

  1. 确认Debian的LC_TIME值:在Debian代理上执行命令,获取当前生效的时间区域配置:

    locale | grep LC_TIME
    

    通常输出类似 LC_TIME="en_GB.UTF-8"(欧洲地区locale会采用日在前、月在后的格式)。

  2. 在Ubuntu上安装对应locale(若未安装):

    sudo locale-gen en_GB.UTF-8
    
  3. 设置Ubuntu的LC_TIME为Debian同款:

    • 临时生效(仅当前会话):
      export LC_TIME=en_GB.UTF-8
      
      执行date命令验证格式是否变为Debian样式。
    • 永久生效(系统全局):
      sudo update-locale LC_TIME=en_GB.UTF-8
      
      重启Ubuntu代理或重新登录后,系统时间格式将与Debian一致。

二、调整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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 15:15:39