Ser*_*nov 0 java datetime scala
我正在做一个简单的练习,Scala试图将莫斯科时间转换为伦敦和纽约
import java.text.SimpleDateFormat
import java.util.TimeZone
inputFormat.setTimeZone(TimeZone.getTimeZone("Europe/Moscow"))
val inMoscow = inputFormat.parse("2020-03-19 12:44 Z")
inMoscow: java.util.Date = Thu Mar 19 12:44:00 MSK 2020
Run Code Online (Sandbox Code Playgroud)
让我们尝试将时间表示形式转换为伦敦:
val outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm Z")
outputFormat.setTimeZone(TimeZone.getTimeZone("Europe/London"))
val outLondon = outputFormat.format(inMoscow)
outputFormat: SimpleDateFormat = java.text.SimpleDateFormat@c07fb1f4
outLondon: String = "2020-03-19 09:44 +0000"
Run Code Online (Sandbox Code Playgroud)
一切正常。但是,当我尝试转换为纽约时间时,会得到意外的结果:
val outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm")
outputFormat.setTimeZone(TimeZone.getTimeZone("Americas/New_York"))
val outNY = outputFormat.format(inMoscow)
outputFormat: SimpleDateFormat = java.text.SimpleDateFormat@ba23d43a
outNY: String = "2020-03-19 09:44"
Run Code Online (Sandbox Code Playgroud)
和伦敦一样。我错过了什么?提前致谢!