如何将时间戳字符串转换为另一个时区的时间戳

我有一个 UTC 时间戳字符串


val x = "2018-09-26T15:05:19.1121042Z"

我想要一个这样的函数来将它转换为 CST 时区中的时间戳对象。


def StringToTimeStamp(str: String): Timestamp = {

  val timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")

  val timeZone = TimeZone.getTimeZone("America/Chicago")

  timeFormat.setTimeZone(timeZone);

  val now = timeFormat.format(str)

  val ts = java.sql.Timestamp.valueOf(now)

  ts

}

但是,我不知道SimpleDateFormat我的字符串的格式,因为我不能输入像 T/Z 这样的字母,因为它们出现在我的字符串中x。我将如何做到这一点?


喵喔喔
浏览 207回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java