【发布时间】:2020-10-04 01:41:19
【问题描述】:
我使用 Jenkins 服务器版本 2.204.2。 Jenkins 在 Apache Tomcat 中运行
我运行以下代码:
pipeline {
agent { node { label 'master' } }
options {
timestamps()
}
stages {
stage('Test') {
steps {
script {
String stamp = new Date().format("YYYY.MM.dd HH:mm:ss")
println("Stamp 1 : ${stamp}")
String stamp2 = new Date().format("YYYY.MM.dd HH:mm:ss", TimeZone.getTimeZone("Asia/Jerusalem"))
println("Stamp 2 : ${stamp2}")
}}}}}
输出(当地时间现在是 18:30。我的时区是亚洲/耶路撒冷)是:
18:30:02 邮票 1 : 2020.06.14 15:30:02
18:30:02 邮票 2 : 2020.06.14 18:30:02
在系统信息页面 (http:///jenkins/systemInfo) 我看到 user.timezone=Asia/Jerusalem
为什么默认 new Date() 返回错误的时间? 相同的代码在另一台服务器上正常工作
谢谢
更新:此代码在 master 上运行。
【问题讨论】: