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


Golang Time.Nanosecond方法代码示例

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


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

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

示例2: MonteCarloCons

func MonteCarloCons(f Function2, cons Constraint2, xMin float64, xMax float64, yMin float64, yMax float64) []float64 {
	var seed time.Time
	seed = time.Now()
	rand.Seed(int64(seed.Nanosecond()))

	//get an inital best-value estimate based on the minimum values for the optimization range
	x := xMin
	y := yMin
	eval := f(x, y)
	xRange := xMax - xMin
	yRange := yMax - yMin
	maxValues := []float64{eval, x, y} //store the best values seen so far
	for i := 0; i < 1e6; i++ {

		//assign a new random value for x and y
		x = rand.Float64()*xRange + xMin
		y = rand.Float64()*yRange + yMin

		//decide if the random values lie within the given constraint function
		if cons(x, y) {
			eval = f(x, y)
			if eval >= maxValues[0] {
				maxValues = []float64{eval, x, y}
			}
		}
	}
	return []float64{maxValues[1], maxValues[2]}
}
开发者ID:alecloudenback,项目名称:goptimize,代码行数:28,代码来源:monteCarlo.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: drawNeedle

func (s *simClock) drawNeedle(t time.Time) {
	s.Save()
	defer s.Restore()
	needle := func(angle float64, lineWidth float64, ratio float64, color string) {
		s.BeginPath()
		s.StrokeStyle = color
		s.LineWidth = lineWidth
		r := s.r * ratio
		angle = angle - math.Pi/2
		x := r * math.Cos(angle)
		y := r * math.Sin(angle)
		s.MoveTo(0, 0)
		s.LineTo(x, y)
		s.Stroke()
	}
	// houre
	angleHour := float64(t.Hour()) / 6.0 * math.Pi
	needle(angleHour, 5.0, s.hourNeedleRatio, "black")
	// minute
	angleMinute := float64(t.Minute()) / 30.0 * math.Pi
	needle(angleMinute, 3.0, s.minuteNeedleRatio, "black")
	// second
	angleSecond := (float64(t.Second()) + float64(t.Nanosecond())/1000000000.0) / 30.0 * math.Pi
	needle(angleSecond, 1.0, s.secondNeedleRatio, "red")
}
开发者ID:theclapp,项目名称:js,代码行数:25,代码来源:clock.go

示例5: dateSize

// dateSize returns the size needed to store a given time.Time.
func dateSize(v time.Time) (length uint8) {
	var (
		month, day, hour, min, sec uint8
		year                       uint16
		msec                       uint32
	)

	year = uint16(v.Year())
	month = uint8(v.Month())
	day = uint8(v.Day())
	hour = uint8(v.Hour())
	min = uint8(v.Minute())
	sec = uint8(v.Second())
	msec = uint32(v.Nanosecond() / 1000)

	if hour == 0 && min == 0 && sec == 0 && msec == 0 {
		if year == 0 && month == 0 && day == 0 {
			return 0
		} else {
			length = 4
		}
	} else if msec == 0 {
		length = 7
	} else {
		length = 11
	}
	length++ // 1 extra byte needed to store the length itself
	return
}
开发者ID:nirbhayc,项目名称:mysql,代码行数:30,代码来源:prot_binary.go

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

示例7: main

func main() {
	p := fmt.Println
	var t time.Time = time.Now()
	fmt.Println(t)
	fmt.Println(t.Format(time.RFC3339))
	fmt.Println(t.Format(time.RFC3339Nano))

	t1, e := time.Parse(
		time.RFC3339,
		"2012-11-01T22:08:41-04:00")
	p(t1)

	p(t.Format("3:04PM"))
	p(t.Format("Mon Jan _2 15:04:05 2006"))
	p(t.Format("2006-01-02T15:04:05.999999-07:00"))
	form := "3 04 PM"
	t2, e := time.Parse(form, "8 41 PM")
	p(t2)
	fmt.Printf("%d - %02d - %02d T %02d : %02d : %02d . %d -00:00\n",
		t.Year(), t.Month(), t.Day(),
		t.Hour(), t.Minute(), t.Second(), t.Nanosecond())
	ansic := "Mon Jan _2 15:04:05 2006"
	_, e = time.Parse(ansic, "8:41PM")
	p(e)
}
开发者ID:trsathya,项目名称:go,代码行数:25,代码来源:timeFormatting.go

示例8: TruncDate

// remove the time component of a datetime to get just a date at 00:00:00
func TruncDate(t time.Time) time.Time {
	hour, min, sec := t.Clock()
	nano := t.Nanosecond()

	d := time.Duration(0) - (time.Duration(nano) + time.Duration(sec)*time.Second + time.Duration(min)*time.Minute + time.Duration(hour)*time.Hour)
	return t.Add(d)
}
开发者ID:JamesDunne,项目名称:StockWatcher,代码行数:8,代码来源:util.go

示例9: calculateElapsedSteps

func (r *Rrd) calculateElapsedSteps(timestamp time.Time) ElapsedPdpSteps {
	interval := float64(timestamp.Sub(r.LastUpdate).Nanoseconds()) / 1e9

	procPdpAge := r.LastUpdate.Unix() % int64(r.Step/time.Second)
	procPdpSt := r.LastUpdate.Unix() - procPdpAge

	occuPdpAge := timestamp.Unix() % int64(r.Step/time.Second)
	occuPdpSt := timestamp.Unix() - occuPdpAge

	var preInt float64
	var postInt float64
	if occuPdpSt > procPdpSt {
		preInt = float64(occuPdpSt - r.LastUpdate.Unix())
		preInt -= float64(r.LastUpdate.Nanosecond()) / 1e9
		postInt = float64(occuPdpAge)
		postInt += float64(timestamp.Nanosecond()) / 1e9
	} else {
		preInt = interval
		postInt = 0
	}

	procPdpCount := procPdpSt / int64(r.Step/time.Second)

	return ElapsedPdpSteps{
		Interval:     interval,
		Steps:        uint64(occuPdpSt-procPdpSt) / uint64(r.Step/time.Second),
		PreInt:       preInt,
		PostInt:      postInt,
		ProcPdpCount: uint64(procPdpCount),
	}
}
开发者ID:untoldwind,项目名称:gorrd,代码行数:31,代码来源:rrd_elapsed_steps.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: StoreLastUpdate

func (f *RrdRawFile) StoreLastUpdate(lastUpdate time.Time) error {
	writer := f.dataFile.Writer(f.baseHeaderSize)
	if err := writer.WriteUnival(unival(lastUpdate.Unix())); err != nil {
		return errors.Wrap(err, 0)
	}
	return writer.WriteUnival(unival(lastUpdate.Nanosecond() / 1000))
}
开发者ID:untoldwind,项目名称:gorrd,代码行数:7,代码来源:rrd_raw_live_head.go

示例12: quakeProto

func quakeProto(r *http.Request, h http.Header, b *bytes.Buffer) *weft.Result {
	if res := weft.CheckQuery(r, []string{}, []string{}); !res.Ok {
		return res
	}

	var q haz.Quake
	var res *weft.Result

	if q.PublicID, res = getPublicIDPath(r); !res.Ok {
		return res
	}

	var t time.Time
	var mt time.Time
	var err error

	if err = db.QueryRow(quakeProtoSQL, q.PublicID).Scan(&t, &mt,
		&q.Depth, &q.Magnitude, &q.Locality, &q.Mmi, &q.Quality,
		&q.Longitude, &q.Latitude); err != nil {
		return weft.ServiceUnavailableError(err)
	}

	q.Time = &haz.Timestamp{Sec: t.Unix(), Nsec: int64(t.Nanosecond())}
	q.ModificationTime = &haz.Timestamp{Sec: mt.Unix(), Nsec: int64(mt.Nanosecond())}

	var by []byte

	if by, err = proto.Marshal(&q); err != nil {
		return weft.ServiceUnavailableError(err)
	}

	b.Write(by)
	h.Set("Content-Type", protobuf)
	return &weft.StatusOK
}
开发者ID:gclitheroe,项目名称:haz,代码行数:35,代码来源:quakeProto.go

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

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

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


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