func main() { time := time.Now() switch { case time.Hour() < 12: fmt.Println("Before noon") default: fmt.Println("Afternoon") } }
func main() { switch time.Now().Weekday() { case time.Saturday, time.Sunday: fmt.Println("it's weekend") default: fmt.Println("it's weekday") } time := time.Now() fmt.Println(time) fmt.Println(time.Hour()) if time.Hour() < 12 { fmt.Println("it's before noon") } else { fmt.Println("is's after noon") } }
func main() { //現在時刻の取得 time := time.Now() //時刻を文字列にフォーマットして出力 fmt.Printf("%04d/%02d/%02d %02d:%02d:%02d\n", time.Year(), time.Month(), time.Day(), time.Hour(), time.Minute(), time.Second()) }
func convertRFC3339ToSyoboiFormat(str string) (string, error) { time, err := time.Parse(time.RFC3339, str) if err != nil { return "", err } return fmt.Sprintf( "%04d%02d%02d_%02d%02d%02d", time.Year(), time.Month(), time.Day(), time.Hour(), time.Minute(), time.Second(), ), nil }
// Issue 11334. func TestUnderscoreTwoThousand(t *testing.T) { format := "15:04_20060102" input := "14:38_20150618" time, err := Parse(format, input) if err != nil { t.Error(err) } if y, m, d := time.Date(); y != 2015 || m != 6 || d != 18 { t.Errorf("Incorrect y/m/d, got %d/%d/%d", y, m, d) } if h := time.Hour(); h != 14 { t.Errorf("Incorrect hour, got %d", h) } if m := time.Minute(); m != 38 { t.Errorf("Incorrect minute, got %d", m) } }
func main() { wsf_api_key := os.Getenv("WSFAPI") wsf_api_url := "http://www.wsdot.wa.gov/Ferries/API/Schedule/rest/scheduletoday/5/TRUE" var wsf_sched_url string if len(wsf_api_key) > 1 { wsf_sched_url = fmt.Sprintf("%s?apiaccesscode=%s", wsf_api_url, wsf_api_key) } else { fmt.Println("To use this tool you must set the WSFAPI environment variable with your WSF API Access Code.") fmt.Println("Obtain an access code at http://www.wsdot.wa.gov/traffic/api/") os.Exit(1) } r, _ := http.Get(wsf_sched_url) b, _ := ioutil.ReadAll(r.Body) //fmt.Println(string(b)) var s Schedule json.Unmarshal(b, &s) fmt.Println(s.ScheduleName) for _, v := range s.TerminalCombos { //fmt.Printf("Got: %d - %+v\n", k, v) fmt.Println(v.DepartingTerminalName, "-->", v.ArrivingTerminalName, v.SailingNotes) for _, times := range v.Times { time := apidate(times.DepartingTime) fmt.Printf(" %2d:%02d -- %s (%d)\n", time.Hour(), time.Minute(), times.VesselName, times.VesselPositionNum) } } }
func printMsg(chatMsg *chatMsg) { if chatMsg.User == user { return } if chatMsg.Type == MsgTypeBroadcast { printSimpleMsg(chatMsg) } else { time := time.Unix(chatMsg.Time, 0) fmt.Printf("%s %d-%d-%d %d:%d:%d :\n", chatMsg.User, time.Year(), time.Month(), time.Day(), time.Hour(), time.Minute(), time.Second()) fmt.Println(chatMsg.Msg) } }
func _() { time := time.Now() fmt.Println(time.Hour()) }