I have two different formats for data and I am trying to have a common format.
Format A
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
Sample time:
2020-09-10T22:40:58.807+00:00
Format B
"yyyy-MM-dd'T'HH:mm:ss.SSSSSSSX"
Sample time:
2020-07-23T02:46:04.0978382Z
I am trying to merge them into one common format and eventually use them for a SQL Dataframe with type Timestamp. I have been using SimpleDateFormat for format A, and for Format B I cannot parse with SimpleDateFormat as it doesn't support Nanoseconds, so instead have been using
val inFormat = DateTimeFormatter.ofPattern(timestampFormat)
val localDatetime = LocalDateTime.parse(timestampString, inFormat)
Timestamp.valueOf(localDatetime) // converting Datetime to timestamp
After using the above my Format B sample time is 2020-07-23 02:46:04.0978382 While format A using SimpleDateFormat is 2020-09-10 22:40:58.807
How can I create a common format for both A and B to be later used into a SQL table? My goal is for whats in format A matches what is in format B(granularity too).
Something that I am trying is using OffsetDateTime to convert both formats. With OffSetDateTime I will
import java.time.OffsetDateTime
val odt = OffsetDateTime.parse(2020-07-23T02:46:04.0978382Z)
println(odt)
In this case, seems like I would truncate offsetDatetime? Is this a good approach?
Thanks