time-go/time.go
2021-10-14 16:05:56 -04:00

27 lines
576 B
Go

package main
import (
"fmt"
"net/http"
"time"
)
func getTime(location string) time.Time {
loc, _ := time.LoadLocation("UTC")
return time.Now().In(loc)
}
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, getTime("UTC").Format("2006-01-02 15:04:05"))
})
http.HandleFunc("/diy", func(w http.ResponseWriter, r *http.Request) {
now := getTime("UTC")
fmt.Fprintf(w, "%s%d", string(now.Format("06")[1]), now.YearDay())
})
listen := ":8000"
fmt.Println("Listening on " + listen)
http.ListenAndServe(listen, nil)
}