This question already has an answer here:
This is a part of a bigger code. I am little confused that if I use any other digit in the below format it results in wrong values.
so instead of
fmt.Println(time.Now().Format("2006-01-02 15:04:05-07:00"))
if I try to use
fmt.Println(time.Now().Format("2006-01-02 12:04:05-04:00"))
Result is wrong. Even when it is same format, just digit change
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println(time.Now().Format("2006-01-02 15:04:05-07:00"))
}
So my question is why is it so. Digits inside format have no meaning. They are just for representation of the format.
</div>
From https://golang.org/pkg/time/:
func (Time) Format
func (t Time) Format(layout string) string
Format returns a textual representation of the time value formatted according to layout, which defines the format by showing how the reference time, defined to be
Mon Jan 2 15:04:05 -0700 MST 2006
would be displayed if it were the value;
So you must use the reference time. You should not change it to another time.