is it possible to use constants instead of digits in Format func
time.Unix(1392899576, 0).Format(stdLongYear +"/"+ stdZeroMonth +"/"+ stdZeroDay)
instead of
time.Unix(1392899576, 0).Format("2006/01/02")
is it possible to use constants instead of digits in Format func
time.Unix(1392899576, 0).Format(stdLongYear +"/"+ stdZeroMonth +"/"+ stdZeroDay)
instead of
time.Unix(1392899576, 0).Format("2006/01/02")
No you cant. Those constant start with a lower case letter and thus are not exported.
the only way to mimic that package is to either copy it or to re-create the constants in your own package like below:
package main
import (
"fmt"
"time"
)
const (
stdLongYear = "2006"
stdZeroMonth = "01"
stdZeroDay = "02"
)
func main() {
fmt.Println(time.Unix(1392899576, 0).Format(stdLongYear + "/" + stdZeroMonth + "/" + stdZeroDay))
}