Documentation ¶
Index ¶
- Variables
- type TimeZone
- func (z TimeZone) Location() *time.Location
- func (z TimeZone) MarshalJSON() ([]byte, error)
- func (z TimeZone) MarshalText() (text []byte, err error)
- func (z *TimeZone) Scan(value any) error
- func (z TimeZone) String() string
- func (z *TimeZone) UnmarshalJSON(data []byte) error
- func (z *TimeZone) UnmarshalText(text []byte) error
- func (z TimeZone) Value() (driver.Value, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var UTCTimeZone = TimeZone{}
Functions ¶
This section is empty.
Types ¶
type TimeZone ¶
type TimeZone struct {
// contains filtered or unexported fields
}
TimeZone based on time.LoadLocation format, Not support the "Local" time zone. The format is "UTC" or IANA time zone database name. See: https://www.iana.org/time-zones. The zero value means UTC time zone. The UTC time zone always uses a zero value.
Example ¶
package main import ( "fmt" "time" "github.com/min0625/tz" _ "time/tzdata" ) func main() { z, err := tz.LoadTimeZone("America/New_York") if err != nil { panic(err) } fmt.Println(z.String()) fmt.Println(time.Time{}.In(z.Location()).Location().String()) }
Output: America/New_York America/New_York
Example (ZeroValue) ¶
package main import ( "fmt" "github.com/min0625/tz" _ "time/tzdata" ) func main() { z, err := tz.LoadTimeZone("UTC") if err != nil { panic(err) } fmt.Println(z == tz.TimeZone{}) }
Output: true
func LoadTimeZone ¶
func (TimeZone) MarshalJSON ¶
func (TimeZone) MarshalText ¶
func (*TimeZone) Scan ¶
Example ¶
package main import ( "fmt" "time" "github.com/min0625/tz" _ "time/tzdata" ) func main() { var z tz.TimeZone if err := z.Scan("America/New_York"); err != nil { panic(err) } fmt.Println(time.Time{}.In(z.Location()).Location().String()) }
Output: America/New_York
func (*TimeZone) UnmarshalJSON ¶
func (*TimeZone) UnmarshalText ¶
func (TimeZone) Value ¶
Example ¶
package main import ( "fmt" "github.com/min0625/tz" _ "time/tzdata" ) func main() { z, err := tz.LoadTimeZone("America/New_York") if err != nil { panic(err) } v, err := z.Value() fmt.Printf("%v %T %v\n", v, v, err) }
Output: America/New_York string <nil>
Example (ZeroValue) ¶
package main import ( "fmt" "github.com/min0625/tz" _ "time/tzdata" ) func main() { var z tz.TimeZone v, err := z.Value() fmt.Printf("%v %T %v\n", v, v, err) }
Output: UTC string <nil>
Click to show internal directories.
Click to hide internal directories.