Choose the result shape
Use ToUTC for strict HH:mm clock results or ToUTCDateTime for complete calendar-aware results.
Compiled, executable documentation
These examples come directly from the repository's Go source. Run them locally to exercise the real timezone package—there is no browser simulation, remote execution service, or separate implementation.
The generator reads this listing from examples/basic/main.go. It demonstrates a Shanghai date-time crossing into the previous UTC year, followed by the existing clock-only conversion.
go run ./examples/basicExpected output
2025-12-31 17:01:01
00:00// Command basic demonstrates clock-time and date-time conversion from Shanghai local time to UTC.
package main
import (
"fmt"
"log"
"github.com/chengchuu/asiatz"
)
func main() {
utcDateTime, err := asiatz.ShanghaiDateTimeToUTC("2026-01-01 01:01:01")
if err != nil {
log.Fatal(err)
}
fmt.Println(utcDateTime)
utcTime, err := asiatz.ShanghaiToUTC("08:00")
if err != nil {
log.Fatal(err)
}
fmt.Println(utcTime)
}
The source-derived clock and date-time examples are compiled, and their output comments are checked by go test ./....
go test ./...package asiatz_test
import (
"fmt"
"github.com/chengchuu/asiatz"
)
func ExampleShanghaiToUTC() {
utcTime, err := asiatz.ShanghaiToUTC("08:00")
if err != nil {
panic(err)
}
fmt.Println(utcTime)
// Output: 00:00
}
func ExampleToUTC() {
utcTime, err := asiatz.ToUTC(5.5, "05:30")
if err != nil {
panic(err)
}
fmt.Println(utcTime)
// Output: 00:00
}
func ExampleShanghaiDateTimeToUTC() {
utcDateTime, err := asiatz.ShanghaiDateTimeToUTC("2026-01-01 01:01:01")
if err != nil {
panic(err)
}
fmt.Println(utcDateTime)
// Output: 2025-12-31 17:01:01
}
func ExampleToUTCDateTime() {
utcDateTime, err := asiatz.ToUTCDateTime(5.75, "2026-01-01 05:45:30")
if err != nil {
panic(err)
}
fmt.Println(utcDateTime)
// Output: 2026-01-01 00:00:30
}
Use ToUTC for strict HH:mm clock results or ToUTCDateTime for complete calendar-aware results.
Both generic functions accept fixed offsets that resolve to whole minutes, including half-hour and quarter-hour offsets.
The generated API documentation lists every exported conversion function from the current package source.