package main import ( "fmt" "time" ) func main() { s := "2023-12-30" //4BC6 [4,11,12,6] t, err := time.Parse("2006-01-02", s) if err != nil { fmt.Println(err) return } y := Uint2BCD(uint64(t.Year()), true) fmt.Println("year:", y) m := Uint2BCD(uint64(t.Month()), true) fmt.Println("mouth:", m) d := Uint2BCD(uint64(t.Day()), true) fmt.Println("day:", d) } func Uint2BCD(n uint64, isBigEndian bool) []byte { var b []byte //if n < 256 { // b = []byte{0} //} for i := 0; ; i++ { h := (n / 10) % 10 l := n % 10 b = append(b, byte(h<<4|l)) n = n / 100 if n == 0 { break } } if !isBigEndian { return b } l := len(b) var r = make([]byte, l) for i, v := range b { r[l-1-i] = v } return r }