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


Golang Time.Clock方法代码示例

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


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

示例1: 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

示例2: 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

示例3: getEpisodes

func getEpisodes() {
	var episodes []entity.Episode
	var t time.Time

	t = time.Now()
	h, _, _ := t.Clock()

	resp, _ := http.Get("http://api.tvmaze.com/schedule?country=US&date=2014-12-01")
	defer resp.Body.Close()
	json.NewDecoder(resp.Body).Decode(&episodes)

	for _, episode := range episodes {
		timeSlice := strings.Split(episode.Airtime, ":")
		episodeHour, _ := strconv.Atoi(timeSlice[0])
		if episodeHour < (h-1) || episodeHour > (h) {
			continue
		}

		if episode.Show != nil {
			fmt.Println(episode.Show.Name)
			if episode.Show.Network != nil {
				fmt.Println(episode.Show.Network.Name)
			}
		}
		fmt.Println(episode.Name)

		fmt.Println("Airtime: ", episode.Airtime)
		fmt.Println("Episode: ", episode.Number)
		fmt.Println("Season: ", episode.Season)
		fmt.Println("")
	}
}
开发者ID:tonto,项目名称:snapp,代码行数:32,代码来源:main.go

示例4: 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

示例5: appendTimeCommon

func appendTimeCommon(dst []byte, t time.Time) []byte {
	_, month, day := t.Date()

	dst = appendTwoDigits(dst, int(month))
	dst = appendTwoDigits(dst, day)

	hour, min, sec := t.Clock()

	dst = appendTwoDigits(dst, hour)
	dst = appendTwoDigits(dst, min)
	dst = appendTwoDigits(dst, sec)

	_, offset := t.Zone()

	switch {
	case offset/60 == 0:
		return append(dst, 'Z')
	case offset > 0:
		dst = append(dst, '+')
	case offset < 0:
		dst = append(dst, '-')
	}

	offsetMinutes := offset / 60
	if offsetMinutes < 0 {
		offsetMinutes = -offsetMinutes
	}

	dst = appendTwoDigits(dst, offsetMinutes/60)
	dst = appendTwoDigits(dst, offsetMinutes%60)

	return dst
}
开发者ID:achanda,项目名称:go,代码行数:33,代码来源:marshal.go

示例6: 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

示例7: doLog

func (fs *fileStorage) doLog(t time.Time, str string) {
	if fs.logSize > logSizeThreshold {
		// Rotate log file.
		fs.logw.Close()
		fs.logw = nil
		fs.logSize = 0
		rename(filepath.Join(fs.path, "LOG"), filepath.Join(fs.path, "LOG.old"))
	}
	if fs.logw == nil {
		var err error
		fs.logw, err = os.OpenFile(filepath.Join(fs.path, "LOG"), os.O_WRONLY|os.O_CREATE, 0644)
		if err != nil {
			return
		}
		// Force printDay on new log file.
		fs.day = 0
	}
	fs.printDay(t)
	hour, min, sec := t.Clock()
	msec := t.Nanosecond() / 1e3
	// time
	fs.buf = itoa(fs.buf[:0], hour, 2)
	fs.buf = append(fs.buf, ':')
	fs.buf = itoa(fs.buf, min, 2)
	fs.buf = append(fs.buf, ':')
	fs.buf = itoa(fs.buf, sec, 2)
	fs.buf = append(fs.buf, '.')
	fs.buf = itoa(fs.buf, msec, 6)
	fs.buf = append(fs.buf, ' ')
	// write
	fs.buf = append(fs.buf, []byte(str)...)
	fs.buf = append(fs.buf, '\n')
	fs.logw.Write(fs.buf)
}
开发者ID:zramsay,项目名称:geth-tmsp,代码行数:34,代码来源:file_storage.go

示例8: 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

示例9: formatHeader

func (l *Logger) formatHeader(buf *bytes.Buffer, t time.Time, file string, line int, lvl int, reqId string, Func string) {
	if l.prefix != "" {
		buf.WriteString(l.prefix)
	}
	if l.flag&(Ldate|Ltime|Lmicroseconds) != 0 {
		if l.flag&Ldate != 0 {
			year, month, day := t.Date()
			itoa(buf, year, 4)
			buf.WriteByte('/')
			itoa(buf, int(month), 2)
			buf.WriteByte('/')
			itoa(buf, day, 2)
			buf.WriteByte(' ')
		}
		if l.flag&(Ltime|Lmicroseconds) != 0 {
			hour, min, sec := t.Clock()
			itoa(buf, hour, 2)
			buf.WriteByte(':')
			itoa(buf, min, 2)
			buf.WriteByte(':')
			itoa(buf, sec, 2)
			if l.flag&Lmicroseconds != 0 {
				buf.WriteByte('.')
				itoa(buf, t.Nanosecond()/1e3, 6)
			}
			buf.WriteByte(' ')
		}
	}
	if reqId != "" {
		buf.WriteByte('[')
		buf.WriteString(reqId)
		buf.WriteByte(']')
	}
	if l.flag&Llevel != 0 {
		buf.WriteString(levels[lvl])
	}
	if l.flag&Lmodule != 0 {
		buf.WriteByte('[')
		buf.WriteString(Func)
		buf.WriteByte(']')

		buf.WriteByte(' ')
	}
	if l.flag&(Lshortfile|Llongfile) != 0 {
		if l.flag&Lshortfile != 0 {
			short := file
			for i := len(file) - 1; i > 0; i-- {
				if file[i] == '/' {
					short = file[i+1:]
					break
				}
			}
			file = short
		}
		buf.WriteString(file)
		buf.WriteByte(':')
		itoa(buf, line, -1)
		buf.WriteString(": ")
	}
}
开发者ID:Felamande,项目名称:filesync,代码行数:60,代码来源:logext.go

示例10: 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

示例11: createFile

// createFile creates log file with specified timestamp.
// l.mu held
func (l *Logger) createFile(t time.Time) error {
	year, month, day := t.Date()
	hour, min, sec := t.Clock()

	var file string
	switch l.options.Mode {
	case R_Size:
		file = fmt.Sprintf("%s-%04d%02d%02d-%02d%02d%02d", l.options.File, year, month, day, hour, min, sec)
	case R_Hour:
		file = fmt.Sprintf("%s-%04d%02d%02d-%02d", l.options.File, year, month, day, hour)
	case R_Day:
		file = fmt.Sprintf("%s-%04d%02d%02d", l.options.File, year, month, day)
	default: // R_None
		file = l.options.File
	}

	if l.file != nil {
		l.out.Flush()
		l.file.Close()
	}

	f, err := os.OpenFile(file, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0664)
	if err != nil {
		return err
	}

	l.file = f
	l.out = bufio.NewWriterSize(f, bufferSize)
	l.nbytes = 0
	l.hour = hour
	l.day = day

	return nil
}
开发者ID:chasex,项目名称:glog,代码行数:36,代码来源:glog.go

示例12: date

func (log *Logger) date(now time.Time) {
	hour, minute, second := now.Clock()
	year, month, day := now.Date()
	//nsec := now.Nanosecond()
	itoa(&log.buf, year, 4)
	log.buf = append(log.buf, '-')
	itoa(&log.buf, int(month), 2)
	log.buf = append(log.buf, '-')
	itoa(&log.buf, day, 2)
	log.buf = append(log.buf, 'T')
	itoa(&log.buf, hour, 2)
	log.buf = append(log.buf, ':')
	itoa(&log.buf, minute, 2)
	log.buf = append(log.buf, ':')
	itoa(&log.buf, second, 2)
	//log.buf = append(log.buf, '.')
	//itoa(&log.buf, nsec, 9)
	_, off := now.Zone()
	if off == 0 {
		log.buf = append(log.buf, 'Z')
	} else {
		zone := off / 60
		absoff := off
		if zone < 0 {
			log.buf = append(log.buf, '-')
			absoff = -absoff
			zone = -zone
		} else {
			log.buf = append(log.buf, '+')
		}
		itoa(&log.buf, zone/60, 2)
		log.buf = append(log.buf, ':')
		itoa(&log.buf, zone%60, 2)
	}
}
开发者ID:lucy,项目名称:go-log,代码行数:35,代码来源:log.go

示例13: getTimeString

// Trasforma la variabile time passata in ingresso in una stringa ordinata e leggibile
func getTimeString(t time.Time) (date, clock string) {
	hour, min, sec := t.Clock()
	year, month, day := t.Date()
	clock = strings.Join([]string{strconv.Itoa(hour), strconv.Itoa(min), strconv.Itoa(sec)}, ".")
	date = strings.Join([]string{strconv.Itoa(day), month.String(), strconv.Itoa(year)}, "-")
	return
}
开发者ID:portaloffreedom,项目名称:ThinkZone,代码行数:8,代码来源:logs.go

示例14: formatPrefix

func (l *Logger) formatPrefix(level int, t time.Time, file string, line int) {
	// prefix: "D0806 10:45:19.598 bvc.go:100] "
	l.buf = append(l.buf, levelStr[level])

	_, month, day := t.Date()
	l.itoa(int(month), 2)
	l.itoa(day, 2)
	l.buf = append(l.buf, ' ')

	hour, min, sec := t.Clock()
	l.itoa(hour, 2)
	l.buf = append(l.buf, ':')
	l.itoa(min, 2)
	l.buf = append(l.buf, ':')
	l.itoa(sec, 2)
	l.buf = append(l.buf, '.')
	l.itoa(t.Nanosecond()/1e6, 3)
	l.buf = append(l.buf, ' ')

	short := file
	for i := len(file) - 1; i > 0; i-- {
		if file[i] == '/' {
			short = file[i+1:]
			break
		}
	}
	l.buf = append(l.buf, short...)
	l.buf = append(l.buf, ':')
	l.itoa(line, -1)
	l.buf = append(l.buf, "] "...)
}
开发者ID:gofs,项目名称:logex,代码行数:31,代码来源:log.go

示例15: 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


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