-1

I have an application which returns time in different timezones e.g "createtime": "2022-01-20 21:40:59 +0000 UTC" or "createtime": "2022-05-04 04:30:12 -0700 PDT"

I need to use the golang t, err := time.Parse(layout, str) code to parse this and convert it to time type. The issue is that time returned can be in any timezone as above(UTC,PDT, IST) etc and i dont want to specify multiple layouts for time.Parse().

Is there a way to handle this with a single layout?

100MIL
  • 41
  • 1
  • 7
  • 3
    Whats wrong with a layout of "2006-01-02 15:04:05 -0700 MST"? Or just strip the textual timezone before parsing (or the numerical). – Volker May 12 '22 at 07:55
  • 2
    https://go.dev/play/p/cm2EzRhc-1C – mkopriva May 12 '22 at 07:56
  • Thanks the MST time layout works, i didnt know about it and was using specific one for UTC ```2006-01-02 15:04:05 -0700 UTC```. I thought for every different timezone i would need different layout. Still curious why the MST layout works for all the date time stamps? – 100MIL May 13 '22 at 07:59

0 Answers0