I am doing a simple exercise in Scala
trying to convert Moscow time to London and NY
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
Let's try to convert time representation to London:
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"
Everything works as expected. However when I try to convert to NY time I get an unexpected results:
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"
Same as London. What have I missed? Thanks in advance!