我有一个 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。我将如何做到这一点?
相关分类