예제 #1
0
func main() {
	//t := time.Now()

	t1 := time.Now()         //现在是12点整(假设),那t1记录的就是12点整
	t2 := t1.Add(-time.Hour) //那t1的时间点 **加上(Add)** 1个小时,是几点呢?
	fmt.Println(t2)          //13点(呵呵)
	fmt.Println(t2.Format("2006010215"))
	fmt.Println(now.Monday())

	day := 7

	var i, h int
	for i = 1; i <= day; i++ {
		for h = 1; h <= 24; h++ {
			// -h*i 不能直接 t1.Add(-h*i*time.Hour) 会报错
			// invalid operation: time.Hour * h (mismatched types time.Duration and int)
			// 需要使用time.Duration来转变类型.
			t2 := t1.Add(time.Duration(-h*i) * time.Hour)
			fmt.Println(t2.Format("2006010215"))
		}
	}

	//time.Sleep(10 * time.Second)

}
예제 #2
0
func makeFood() {
	//xpath für Beilagen: /html/body/div[@id='menu']/div/div[@class='detail']/p/text()
	//xpath für Gerichte: /html/body/div[@id='menu']/div/div[@class='detail']/p/*/text()
	html := getfood()
	path := xmlpath.MustCompile("/html/body/div[@id='menu']/div/div[@class='detail']/p/text()")
	//fmt.Println(html)
	strong := regexp.MustCompile("<strong>")
	strong2 := regexp.MustCompile("</strong>")

	//	html = strong.replaceAllString(html," strong ")
	//	html = strong2.replaceAllString(html," Strong ")
	html = strong.ReplaceAllString(html, "")
	html = strong2.ReplaceAllString(html, " ")
	root, err := xmlpath.ParseHTML(strings.NewReader(html))
	if err != nil {
		log.Fatal(err)
	}

	c := ical.NewBasicVCalendar()
	c.PRODID = "golang food"
	components := []ical.VComponent{}
	const layout = time.StampNano
	var AddToGetToRightDay = 0
	it := path.Iter(root)
	for it.Next() {
		s := it.Node().String()
		//if s == "" {
		//	break
		//}
		var e ical.VEvent
		e.UID = string(time.Now().Format(layout))
		e.DTSTAMP = time.Now()
		//t2 := now.AddDate(0, 0, 7).Format(layout)
		Day := now.Monday().AddDate(0, 0, AddToGetToRightDay)
		hours, _ := time.ParseDuration("11h")
		hoursah, _ := time.ParseDuration("0.5h")
		DayWTime := Day.Add(hours)
		e.DTSTART = DayWTime
		e.DTEND = DayWTime.Add(hoursah)
		e.SUMMARY = s
		if AddToGetToRightDay == 4 {
			AddToGetToRightDay = 0

		} else {
			AddToGetToRightDay++
		}

		components = append(components, &e)
		//		fmt.Println(string(e.DTSTART.Format(layout)) + ":")
		//		fmt.Println(s)
	}
	c.VComponent = components
	fmt.Print("content-type: text/plain; charset=utf-8\r\n")
	fmt.Print("\r\n")
	c.Encode(os.Stdout)
}