当前位置: 首页>>代码示例>>Golang>>正文


Golang Time.Date方法代码示例

本文整理汇总了Golang中Time.Time.Date方法的典型用法代码示例。如果您正苦于以下问题:Golang Time.Date方法的具体用法?Golang Time.Date怎么用?Golang Time.Date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Time.Time的用法示例。


在下文中一共展示了Time.Date方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetGame

func GetGame(id string, t time.Time) (Game, error) {
	y, m, d := t.Date()

	url := fmt.Sprintf(GamedayBaseUrl+"/year_%d/month_%02d/day_%02d/epg.xml", y, m, d)

	resp, err := http.Get(url)

	if err != nil {
		return Game{}, err
	}

	var s Schedule

	err = Load(resp.Body, &s)

	if err != nil {
		return Game{}, err
	}

	for _, game := range s.Games {
		if game.HomeTeamId == id || game.AwayTeamId == id {
			return game, nil
		}
	}

	return Game{}, fmt.Errorf("Team %s doesn't have a game on %s", id, t)
}
开发者ID:kyleconroy,项目名称:gameday,代码行数:27,代码来源:gameday.go

示例2: newTime

func newTime(now time.Time) *Time {
	year, _month, day := now.Date()
	month := int(_month)
	_, week := now.ISOWeek()
	hour := now.Hour()
	return &Time{year, month, day, hour, week}
}
开发者ID:simonz05,项目名称:metrics,代码行数:7,代码来源:bitmap_test.go

示例3: formatHeader

func (l *Logger) formatHeader(t time.Time) string {
	var s string

	//*buf = append(*buf, l.prefix...)
	if l.flag&(Ldate|Ltime|Lmicroseconds) != 0 {
		if l.flag&Ldate != 0 {
			year, month, day := t.Date()
			s += itoa(year, 4)
			s += "/"
			s += itoa(int(month), 2)
			s += "/"
			s += itoa(day, 2)
		}
		if l.flag&(Ltime|Lmicroseconds) != 0 {
			hour, min, sec := t.Clock()

			s += " "
			s += itoa(hour, 2)
			s += ":"
			s += itoa(min, 2)
			s += ":"
			s += itoa(sec, 2)
			if l.flag&Lmicroseconds != 0 {
				s += "."
				s += itoa(t.Nanosecond()/1e3, 6)
			}
		}

		s += " "
	}
	return s
}
开发者ID:alviezhang,项目名称:go-socks5,代码行数:32,代码来源:logger.go

示例4: TDateMax

func TDateMax(dt TDate, t time.Time) int {
	if dt == TDay {
		year, month, _ := t.Date()
		return DaysInMonth(int(month), year)
	}
	return td_limits[dt]
}
开发者ID:xiilei,项目名称:cronweb,代码行数:7,代码来源:time.go

示例5: parseDateTime

func parseDateTime(str string, loc *time.Location) (time.Time, error) {
	var t time.Time
	var err error

	base := "0000-00-00 00:00:00.0000000"
	switch len(str) {
	case 10, 19, 21, 22, 23, 24, 25, 26:
		if str == base[:len(str)] {
			return t, err
		}
		t, err = time.Parse(timeFormat[:len(str)], str)
	default:
		err = ErrInvalidTimestring
		return t, err
	}

	// Adjust location
	if err == nil && loc != time.UTC {
		y, mo, d := t.Date()
		h, mi, s := t.Clock()
		t, err = time.Date(y, mo, d, h, mi, s, t.Nanosecond(), loc), nil
	}

	return t, err
}
开发者ID:leobcn,项目名称:dbr,代码行数:25,代码来源:types.go

示例6: formatHeader

func formatHeader(flag int, t time.Time, file string, line int, funcname string) string {
	var buf bytes.Buffer
	buf.WriteByte('[')
	needspace := false
	if flag&(DateFlag|TimeFlag|MsecFlag) != 0 {
		if flag&DateFlag != 0 {
			year, month, day := t.Date()
			writespace(&buf, needspace)
			fmt.Fprintf(&buf, "%04d/%02d/%02d", year, month, day)
			needspace = true
		}
		if flag&(TimeFlag|MsecFlag) != 0 {
			hour, min, sec := t.Clock()
			writespace(&buf, needspace)
			fmt.Fprintf(&buf, "%02d:%02d:%02d", hour, min, sec)
			if flag&MsecFlag != 0 {
				fmt.Fprintf(&buf, ".%06d", t.Nanosecond()/1e3)
			}
			needspace = true
		}
	}
	if flag&(LongFileFlag|ShortFileFlag|FuncNameFlag) != 0 {
		if flag&ShortFileFlag != 0 {
			file = shortfilename(file)
		}
		writespace(&buf, needspace)
		fmt.Fprintf(&buf, "%s:%d", file, line)
		if flag&FuncNameFlag != 0 {
			fmt.Fprintf(&buf, " (%s)", shortfuncname(funcname))
		}
		needspace = true
	}
	buf.WriteByte(']')
	return buf.String()
}
开发者ID:ironzhang,项目名称:golang,代码行数:35,代码来源:logger.go

示例7:

func (ø *TableForm) SetValues(row *pgsql.Row) {
	props := row.AsStrings()
	for k, v := range props {
		if !ø.HasFieldDefinition(k) {
			continue
		}
		elem := ø.FieldElement(k)
		if elem.Tag() == "select" {
			option := elem.Any(h.And_(h.Attr("value", v), h.Tag("option")))
			if option != nil {
				option.Add(h.Attr("selected", "selected"))
			}
		} else {
			if elem.Tag() == "textarea" {
				elem.Add(v)
			} else {
				//tp := elem.Attribute("type")
				//if tp == "date" {
				if elem.HasClass("date") {
					var tme time.Time
					field := row.Table.Field(k)
					row.Get(field, &tme)
					year, month, day := tme.Date()
					// %02.0f.%02.0f.%4.0f
					v = fmt.Sprintf("%4.0f-%02.0f-%02.0f", float64(year), float64(int(month)), float64(day))
				}
				elem.Add(h.Attr("value", v))
			}
		}
	}
}
开发者ID:metakeule,项目名称:goform,代码行数:31,代码来源:tableform.go

示例8: showMonthCalendar

func showMonthCalendar(t time.Time) {
	year, month, _ := t.Date()

	fmt.Printf("\t\t%v\t\t%v\n", month, year)
	fmt.Println("Sun\tMon\tTue\tWed\tThu\tFri\tSat")

	cal := time.Date(year, month, 1, 0, 0, 0, 0, time.UTC)
	end := cal.AddDate(0, 1, 0)
	if end.Weekday() != 0 {
		end = end.AddDate(0, 0, (int)(6-end.Weekday()))
	} else {
		end = end.AddDate(0, 0, -1)
	}

	cal = cal.AddDate(0, 0, (int)(-cal.Weekday()))

	for !end.Before(cal) {
		if cal.Weekday() == 6 {
			fmt.Println(cal.Day())
		} else {
			fmt.Print(cal.Day(), "\t")
		}
		cal = cal.AddDate(0, 0, 1)
	}
}
开发者ID:sunghau,项目名称:go-example,代码行数:25,代码来源:calendar.go

示例9: GetBetween

func (source mondayAfternoons) GetBetween(start, end time.Time) ([]book.Booking, error) {

	// find next monday
	y, m, d := start.Date()
	daysUntilMonday := int((7 + time.Monday - start.Weekday()) % 7)
	nextmonday := time.Date(y, m, d+daysUntilMonday, 0, 0, 0, 0, start.Location())

	// build a map of booked dates
	bookedSet := make(map[time.Time]bool)
	if booked, err := source.session.List(); err != nil {
		return nil, err
	} else {
		for _, appointment := range booked {
			y, m, d = appointment.Timestamp.Date()
			date := time.Date(y, m, d, 0, 0, 0, 0, start.Location())
			bookedSet[date] = true
		}
	}

	// add a week at a time
	var bookings []book.Booking
	for !nextmonday.After(end) {
		// take days where nothing has been booked yet
		if _, exists := bookedSet[nextmonday]; !exists {
			bookings = append(bookings, lizafternoon{nextmonday})
		}
		nextmonday = nextmonday.AddDate(0, 0, 7)
	}
	return bookings, nil
}
开发者ID:allonhadaya,项目名称:boa,代码行数:30,代码来源:main.go

示例10: TimeWithLocation

// TimeWithLocation returns a time.Time using the given location,
// while using the time values from the given time (day, hour, minutes, etc.)
func TimeWithLocation(l *time.Location, t time.Time) time.Time {
	y, m, d := t.Date()
	if l == nil {
		l = time.UTC
	}
	return time.Date(y, m, d, t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), l)
}
开发者ID:juztin,项目名称:am,代码行数:9,代码来源:time.go

示例11: checkDate

func checkDate(year int, month time.Month, day int, tm time.Time) bool {
	y, m, d := tm.Date()
	if y != year || m != month || d != day {
		return false
	}
	return true
}
开发者ID:pbnjay,项目名称:strptime,代码行数:7,代码来源:strptime_test.go

示例12: ParseTime

func ParseTime(str string, rel time.Time) time.Time {
	if t, ok := tryAll(str, rel, datetimeFormats); ok {
		return t
	}

	var dt, tt time.Time
	var dok, tok bool
	if strings.Index(str, " ") > -1 {
		parts := strings.SplitN(str, " ", 2)
		dt, dok = tryAll(parts[0], rel, dateFormats)
		tt, tok = tryAll(parts[1], rel, timeFormats)
	}
	if !dok || !tok {
		dt, dok = tryAll(str, rel, dateFormats)
		tt, tok = tryAll(str, rel, timeFormats)
	}
	if !dok && !tok {
		return time.Time{}
	}

	y, mo, d := dt.Date()
	if y == 0 {
		y, _, _ = rel.Date()
	}
	h, m, s := tt.Clock()
	return time.Date(y, mo, d, h, m, s, 0, rel.Location())
}
开发者ID:sarifsystems,项目名称:sarif,代码行数:27,代码来源:format.go

示例13: logOneLine

func (w *Logger) logOneLine(asof time.Time, text, port string) {
	// figure out name of logfile based on UTC date, with daily rotation
	year, month, day := asof.Date()
	path := fmt.Sprintf("%s/%d", w.dir, year)
	err := os.MkdirAll(path, os.ModePerm)
	flow.Check(err)
	// e.g. "./logger/2014/20140122.txt"
	datePath := fmt.Sprintf("%s/%d.txt", path, (year*100+int(month))*100+day)

	if w.fd == nil || datePath != w.fd.Name() {
		if w.fd != nil {
			name := w.fd.Name()
			w.fd.Close()
			w.Out.Send(name) // report the closed file
		}
		mode := os.O_WRONLY | os.O_APPEND | os.O_CREATE
		fd, err := os.OpenFile(datePath, mode, os.ModePerm)
		flow.Check(err)
		w.fd = fd
	}
	// append a new log entry, here is an example of the format used:
	// 	L 01:02:03.537 usb-A40117UK OK 9 25 54 66 235 61 210 226 33 19
	hour, min, sec := asof.Clock()
	line := fmt.Sprintf("L %02d:%02d:%02d.%03d %s %s\n",
		hour, min, sec, jeebus.TimeToMs(asof)%1000, port, text)
	w.fd.WriteString(line)
}
开发者ID:jcw,项目名称:housemon,代码行数:27,代码来源:logger.go

示例14: writeTime

func (w *Writer) writeTime(v interface{}, t time.Time) (err error) {
	w.setRef(v)
	s := w.Stream
	year, month, day := t.Date()
	hour, min, sec := t.Clock()
	nsec := t.Nanosecond()
	tag := TagSemicolon
	if t.Location() == time.UTC {
		tag = TagUTC
	}
	if hour == 0 && min == 0 && sec == 0 && nsec == 0 {
		if _, err = s.Write(formatDate(year, int(month), day)); err == nil {
			err = s.WriteByte(tag)
		}
	} else if year == 1970 && month == 1 && day == 1 {
		if _, err = s.Write(formatTime(hour, min, sec, nsec)); err == nil {
			err = s.WriteByte(tag)
		}
	} else if _, err = s.Write(formatDate(year, int(month), day)); err == nil {
		if _, err = s.Write(formatTime(hour, min, sec, nsec)); err == nil {
			err = s.WriteByte(tag)
		}
	}
	return err
}
开发者ID:hprose,项目名称:hprose-go,代码行数:25,代码来源:writer.go

示例15: getTimeByRangeType

func getTimeByRangeType(myTime *time.Time, rangeType dataRangeType) (beginTime time.Time, endTime time.Time) {
	h, m, s := myTime.Clock()
	y, M, d := myTime.Date()
	wd := myTime.Weekday()
	l := myTime.Location()
	var bh, bm, bs, eh, em, es = h, m, s, h, m, s
	var by, bM, bd, ey, eM, ed = y, M, d, y, M, d

	switch rangeType {
	case PerMinute:
		bh, bm, bs = h, m, 0
		eh, em, es = h, m, 59
		by, bM, bd = y, M, d
		ey, eM, ed = y, M, d
	case PerHour:
		bh, bm, bs = h, 0, 0
		eh, em, es = h, 59, 59
		by, bM, bd = y, M, d
		ey, eM, ed = y, M, d
	case PerDay:
		bh, bm, bs = 0, 0, 0
		eh, em, es = 23, 59, 59
		by, bM, bd = y, M, d
		ey, eM, ed = y, M, d
	case PerWeek:
		bh, bm, bs = 0, 0, 0
		eh, em, es = 23, 59, 59
		by, bM, bd = y, M, d-int(time.Sunday+wd)
		ey, eM, ed = y, M, d+int(time.Saturday-wd)
	case PerMonth:
		bh, bm, bs = 0, 0, 0
		eh, em, es = 23, 59, 59
		by, bM, bd = y, M, 1
		ey, eM, ed = y, M+1, 0
	case PerSeason:
		bh, bm, bs = 0, 0, 0
		eh, em, es = 23, 59, 59
		switch {
		case M >= time.January && M <= time.March:
			by, bM, bd = y, 1, 1
		case M >= time.April && M <= time.June:
			by, bM, bd = y, 4, 1
		case M >= time.July && M <= time.September:
			by, bM, bd = y, 7, 1
		case M >= time.October && M <= time.December:
			by, bM, bd = y, 10, 1
		}
		ey, eM, ed = y, bM+3, 0
	case PerYear:
		bh, bm, bs = 0, 0, 0
		eh, em, es = 23, 59, 59
		by, bM, bd = y, 1, 1
		ey, eM, ed = y, 12, 31
	}

	bt := time.Date(by, bM, bd, bh, bm, bs, 0, l)
	et := time.Date(ey, eM, ed, eh, em, es, 999999999, l)

	return bt, et
}
开发者ID:maozhen,项目名称:easyMonitor,代码行数:60,代码来源:dateRange.go


注:本文中的Time.Time.Date方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。