Re: [go-nuts] Time parsing PDT -> PST

323 views
Skip to first unread message

Kyle Lemons

unread,
Apr 11, 2013, 5:52:36 PM4/11/13
to Greg Furmanek, golang-nuts
Can you show us which part of that output was different than what you expected?


On Wed, Apr 10, 2013 at 10:20 PM, Greg Furmanek <greg.f...@gmail.com> wrote:
Can someone help me with this problem:

Code:

  format :=       "2006-01-02T15:04:05 -0700 MST"
  dateToParse :=  "2006-01-02T15:04:05 -0700 PDT"
  parsedTime, err := time.Parse(format, dateToParse)
  fmt.Println("Error: ", err)
  fmt.Println("Parsed Representation:", parsedTime)
  fmt.Println("Local Representation: ", parsedTime.Local())
  name, offset := time.Now().Zone()
  fmt.Println("Time zone name:  ", name)
  fmt.Println("Time zone offset:", offset)
  currentTime := time.Now()
  fmt.Println("Current time:                  ", currentTime)
  fmt.Println("Current time as Local:         ", currentTime.Local())
  fmt.Println("Current time as UTC -> Local:  ", currentTime.UTC().Local())


Output:

Error:  <nil>
Parsed Representation: 2006-01-02 15:04:05 -0700 PDT
Local Representation:  2006-01-02 14:04:05 -0800 PST

This is the correct representation of a date in Jauary -- PST.
 
Time zone name:   PDT
Time zone offset: -25200
Current time:                   2013-04-10 22:17:49.690857 -0700 PDT
Current time as Local:          2013-04-10 22:17:49.690857 -0700 PDT
Current time as UTC -> Local:   2013-04-10 22:17:49.690857 -0700 PDT

These are all the correct representation of a date during April -- PDT.
 
Why would parsed date changed timezones when time.Now() manages to correctly preserve it?

--
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...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages