Compiled, executable documentation

AsiaTZ examples

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.

Run the basic command

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/basic

Expected output

2025-12-31 17:01:01
00:00

Open the basic example source on GitHub

// 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)
}

Use executable examples

The source-derived clock and date-time examples are compiled, and their output comments are checked by go test ./....

go test ./...

Open the example test source on GitHub

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
}

Continue from working code

Choose the result shape

Use ToUTC for strict HH:mm clock results or ToUTCDateTime for complete calendar-aware results.

Use a custom offset

Both generic functions accept fixed offsets that resolve to whole minutes, including half-hour and quarter-hour offsets.