0

I have a string like this

01/01/2019 8:43:55 AM # dd/MM/yy hh:mm:ss ??

After reading through the docs I concluded that the AM part had no corresponding entry in the formats provided. So that I would have to simply test to see if the string ended in either AM or PM and then adjust the hour part accordingly.

Is there something slicker? I didn't really grasp how to use templates yet, and I notice that the last two methods in the docs mention templates.

SlightlyKosumi
  • 701
  • 2
  • 8
  • 24

1 Answers1

2

I think you are looking for tt (also, your parsing string should be different for the year and the hour):

import times

var dt = parse("01/01/2019 8:43:55 AM", "dd/MM/yyyy H:mm:ss tt")
echo dt
## 2019-01-01T08:43:55+01:00

dt = parse("01/01/2019 8:43:55 PM", "dd/MM/yyyy H:mm:ss tt")
echo dt
## 2019-01-01T20:43:55+01:00
xbello
  • 7,223
  • 3
  • 28
  • 41