On Fri, Apr 21, 2023 at 5:27 PM jlfo...@berkeley.edu <jlforr...@berkeley.edu> wrote: > > Consider the program below. > > I want to compute the duration between a time that I put in the > "old_time_str" variable and the current time. If I put the current time in a > string, the program shows the correct duration. If I get the current time > using time.Now() then the duration shown is 7 hours too long (I'm in PDST). > I'd like both methods to return the correct duration. Let's presume that > both times are in the same time zone. > > What am I doing wrong?
It's timezones. Your time strings don't have any timezone information, and the default differs for time.Parse and time.Now. You will probably get the results you want if you change your calls to time.Parse(t, s) to time.ParseInLocation(t, s, time.Local). See https://pkg.go.dev/time#Parse. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUEEBtFS6UAW9ptZdwo2gTR9DSJ-w6BY%3DfE%2Bj8E2ixADA%40mail.gmail.com.