Exemple #1
0
func main() {

	time := time.Now()                      //calls for current time in string
	minutes := time.Minute()                //call time.minute function for int of current minute
	fmt.Printf("%s\n", "Current time is: ") //Print string
	fmt.Printf("%s\n", time)                //Print Time - type strring

	templ, error := template.ParseFiles("tpl.gohtml") // Parse template file
	if error != nil {
		log.Fatalln(error)
	}

	if minutes%2 == 0 {
		fmt.Printf("%s\n", "The current minute is even")
		fmt.Printf("%d\n", minutes)

		error = templ.Execute(os.Stdout, nil) //Executes template if minute is even.
		if error != nil {
			log.Fatalln(error)
		}

	} else {
		fmt.Printf("%s\n", "The current minute is odd")
		fmt.Printf("%d\n", minutes)
	}

}
Exemple #2
0
func main() {

	time := time.Now()                      //calls for current time in string
	minutes := time.Minute()                //call time.minute function for int of current minute
	fmt.Printf("%s\n", "Current time is: ") //Print string
	fmt.Printf("%s\n", time)                //Print Time - type strring

	fmt.Printf("%s\n", "Time variable is of type: ") //Print string
	fmt.Println(reflect.TypeOf(time))

	fmt.Printf("%s\n", "Minutes variable is of type: ") //Print string
	fmt.Println(reflect.TypeOf(minutes))

}
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())
}
Exemple #4
0
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
}
Exemple #5
0
// 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)
	}
}
Exemple #6
0
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)
		}
	}

}
Exemple #7
0
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)
	}
}