58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
"git.haelnorr.com/h/timefmt"
|
|
)
|
|
|
|
func main() {
|
|
fmt.Println("=== timefmt Demo ===\n")
|
|
|
|
// 1. Building a custom format
|
|
fmt.Println("1. Building a custom format:")
|
|
format := timefmt.NewBuilder().
|
|
Year4().Dash().
|
|
MonthNumeric2().Dash().
|
|
DayNumeric2().Space().
|
|
Hour24().Colon().
|
|
Minute().Colon().
|
|
Second().
|
|
Build()
|
|
|
|
fmt.Printf(" Go format: %s\n", format.GoFormat())
|
|
fmt.Printf(" LDML: %s\n", format.LDML())
|
|
fmt.Printf(" Description: %s\n\n", format.Description())
|
|
|
|
// 2. Using pre-built formats
|
|
fmt.Println("2. Pre-built formats:")
|
|
now := time.Now()
|
|
fmt.Printf(" ISO8601: %s\n", timefmt.ISO8601.Format(now))
|
|
fmt.Printf(" DateTime: %s\n", timefmt.DateTime.Format(now))
|
|
fmt.Printf(" DateUS: %s\n", timefmt.DateUS.Format(now))
|
|
fmt.Printf(" Kitchen: %s\n\n", timefmt.Kitchen.Format(now))
|
|
|
|
// 3. Parsing existing Go formats
|
|
fmt.Println("3. Parsing an existing Go format:")
|
|
parsed, _ := timefmt.ParseGoFormat("02/01/2006")
|
|
fmt.Printf(" Input: 02/01/2006\n")
|
|
fmt.Printf(" LDML: %s\n", parsed.LDML())
|
|
fmt.Printf(" Description: %s\n\n", parsed.Description())
|
|
|
|
// 4. Complex format example
|
|
fmt.Println("4. Complex format with custom text:")
|
|
complex := timefmt.NewBuilder().
|
|
WeekdayFull().Comma().
|
|
MonthFull().Space().
|
|
DayNumeric().Comma().
|
|
Year4().Space().
|
|
Literal("at").Space().
|
|
Hour12().Colon().
|
|
Minute().Space().
|
|
AMPM().
|
|
Build()
|
|
|
|
fmt.Printf(" Formatted: %s\n", complex.Format(now))
|
|
fmt.Printf(" LDML: %s\n", complex.LDML())
|
|
}
|