-2

I am getting date from snowflake in below format

2021-07-13 00:00:00.000 -0600

What string format should i use to convert it to java 8 LocalDateTime?

Olivier Grégoire
  • 33,839
  • 23
  • 96
  • 137
  • 1
    Have you checked the documentation of a parsing format? Or taken a look at other examples? – f1sh Jul 13 '21 at 08:35
  • 1
    Why `LocalDateTime` when there is an offset of `-0600`? Use an `OffsetDateTime` and parse it with a `DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss.SSS x")`. You can extract a `LocalDateTime` from the `OffsetDateTime` afterwards, there's a method `.toLocalDateTime()`. – deHaar Jul 13 '21 at 08:45
  • `LocalDateTime` is much overused and not the right class for you to use here, as @deHaar already spotted. In which time zone do you want the result? If there is an answer to that question, convert to a `ZonedDateTime`. It gives you everything that a `LocalDateTime` can give you and more. If you are happy with the UTC offset from the string (-0600 in the example), just parse into an `OffsetDateTime`. – Ole V.V. Jul 13 '21 at 10:47

1 Answers1

0

Use yyyy-MM-dd HH:mm:ss,SSS ZZZZ

Minnow
  • 495
  • 4
  • 6
  • 2
    Details, you probably wanted a dot rather than a comma between `ss` and `SSS`. Otherwise I believe it’s correct. – Ole V.V. Jul 13 '21 at 10:44