本文整理汇总了Golang中os.Time函数的典型用法代码示例。如果您正苦于以下问题:Golang Time函数的具体用法?Golang Time怎么用?Golang Time使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Time函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: readHosts
func readHosts() {
now, _, _ := os.Time()
hp := hostsPath
if len(hosts.data) == 0 || hosts.time+cacheMaxAge <= now || hosts.path != hp {
hs := make(map[string][]string)
var file *file
if file, _ = open(hp); file == nil {
return
}
for line, ok := file.readLine(); ok; line, ok = file.readLine() {
if i := byteIndex(line, '#'); i >= 0 {
// Discard comments.
line = line[0:i]
}
f := getFields(line)
if len(f) < 2 || ParseIP(f[0]) == nil {
continue
}
for i := 1; i < len(f); i++ {
h := f[i]
hs[h] = append(hs[h], f[0])
}
}
// Update the data cache.
hosts.time, _, _ = os.Time()
hosts.path = hp
hosts.data = hs
file.close()
}
}
示例2: main
func main() {
sec, nsec, _ := os.Time()
ts := bridge.GetValidTables(0, " P P1C P1H P3H P4H P P P", 100, bridge.DefaultConventions())
fmt.Println("Conventions are:", ts.Conventions)
fmt.Println(ts)
ts = bridge.GetValidTables(0, " P 1C1H P2H P3H P4H P P P", 100, bridge.DefaultConventions())
fmt.Println("Conventions are:", ts.Conventions)
fmt.Println(ts)
sec2, nsec2, _ := os.Time()
name, _ := os.Hostname()
dt := float64(sec2-sec) + 1e-9*float64(nsec2-nsec)
timelimits := map[string]float64{"collins": 1.7, "morland": 13, "bennet": 4, "bingley": 3}
fmt.Println("It took ", dt, "seconds on", name)
expected, ok := timelimits[name]
if ok {
if dt > expected {
fmt.Println("Exceeded expected time by", dt-expected, "seconds.")
os.Exit(1)
}
fmt.Println("Expected", expected, "seconds on", name)
} else {
fmt.Println("You should add statistics for", name)
os.Exit(1)
}
}
示例3: MkDir
func (fs *FileSystem) MkDir(parent uint64, name string) *Inode {
if parent != 1 {
// Let's check that the parent actually exists...
if _, ok := fs.nodes[parent]; !ok {
panic("yikes, the parent doesn't exist!")
}
}
var a = new(Inode)
a.Ino = fs.maxino + 1
fs.maxino = a.Ino
a.Mode = fuse.S_IFDIR + 0755
a.Uid = 1137
a.Gid = 1137
a.Nlink = 1
sec, nsec, _ := os.Time()
a.Mtime = uint64(sec) - 3600
a.Mtimensec = uint32(nsec)
a.Ctime = uint64(sec) - 3600
a.Ctimensec = uint32(nsec)
a.DirContents = make(map[string]uint64)
// Create . and .. entries here
//a.DirContents["."] = a.Ino
//a.DirContents[".."] = parent
fs.nodes[a.Ino] = a
// Add entry to parent directoory
if name != "." {
fs.nodes[parent].DirContents[name] = a.Ino
}
return a
}
示例4: Nanoseconds
// Nanoseconds reports the number of nanoseconds since the Unix epoch,
// January 1, 1970 00:00:00 UTC.
func Nanoseconds() int64 {
sec, nsec, err := os.Time()
if err != nil {
panic(err)
}
return sec*1e9 + nsec
}
示例5: Seconds
// Seconds reports the number of seconds since the Unix epoch,
// January 1, 1970 00:00:00 UTC.
func Seconds() int64 {
sec, _, err := os.Time()
if err != nil {
panic(err)
}
return sec
}
示例6: Nanoseconds
// Nanoseconds reports the number of nanoseconds since the Unix epoch,
// January 1, 1970 00:00:00 UTC.
func Nanoseconds() int64 {
sec, nsec, err := os.Time()
if err != nil {
panic("time: os.Time: ", err.String())
}
return sec*1e9 + nsec
}
示例7: Seconds
// Seconds reports the number of seconds since the Unix epoch,
// January 1, 1970 00:00:00 UTC.
func Seconds() int64 {
sec, _, err := os.Time()
if err != nil {
panic("time: os.Time: ", err.String())
}
return sec
}
示例8: newEntry
func newEntry(key string, value interface{}) *entry {
var t time
t.Sec, t.Nsec, _ = os.Time()
return &entry{record{key, value}, t, false, nil}
}
示例9: lock
func (world *World) lock() (err os.Error) {
if world.lockfd != nil {
panic("lock fd already exists... should never happen")
}
sessionLockPath := path.Join(world.dir, sessionlock)
world.lockfd, err = os.Open(sessionLockPath, os.O_RDWR|os.O_ASYNC, 0000)
if err != nil {
error.NewError(fmt.Sprint("could not open ", sessionlock), nil)
}
// minecraft's locking mechanism is peculiar.
// It writes the current system time in milliseconds since 1970 to the file.
// It then watches the file for changes. If a change is monitored, it aborts.
// This has strange implications, such as the LAST process to open the world owns it,
// not the first.
// but hey, when in rome...
sec, nsec, err := os.Time()
if err != nil {
err = error.NewError("couldn't get the current time..?!", err)
return
}
world.lockmsec = (sec * 1000) + (nsec / 1000000)
err = nbt.WriteInt64(world.lockfd, world.lockmsec)
if err != nil {
err = error.NewError("could not write timestamp to session lock", err)
return
}
return
}
示例10: Now
func (s *pollServer) Now() int64 {
sec, nsec, err := os.Time()
if err != nil {
panic("net: os.Time: ", err.String())
}
nsec += sec * 1e9
return nsec
}
示例11: getTime
func getTime() float64 {
sec, nsec, err := os.Time()
var time float64 = 0
if err == nil {
time = float64(sec) + (float64(nsec) * math.Pow10(-9))
}
return time
}
示例12: expire
func expire(minutes int) (expires string) {
secondsNow, _, _ := os.Time()
addSeconds := minutes * 60
secondsNew := int(secondsNow)
expiresInt := secondsNew + addSeconds
expires = strconv.Itoa(expiresInt)
return
}
示例13: TilePlane
func TilePlane(maxtiles int, tileSymmetry string, showIntermediate bool) (<-chan *quadratic.Map, chan int) {
finalTilings := make(chan *quadratic.Map, 10000)
halt := make(chan int, 1)
go tileDriver(TileMap("adehnrvuwtspjgbc", 0), finalTilings, halt, chooseNextEdgeByLocation, maxtiles, tileSymmetry, showIntermediate)
initializationTime, _, _ = os.Time()
fmt.Fprintf(os.Stderr, "intitialized at %v\n", initializationTime)
return finalTilings, halt
}
示例14: Copy
// returns an equivalent but completlely independent copy of b
func (b *Board) Copy() *Board {
sec, nsec, _ := os.Time()
l := b.boardSize * b.boardSize
cpy := &Board{
fields: make([]*Group, l),
colorOfNextPlay: b.colorOfNextPlay,
boardSize: b.boardSize,
currentSequence: b.currentSequence,
actionOnNextBlackMove: make([]*actionFunc, l),
actionOnNextWhiteMove: make([]*actionFunc, l),
fieldSequencesBlack: make([]uint32, l),
fieldSequencesWhite: make([]uint32, l),
rand: rand.New(rand.NewSource(sec + nsec)),
prisonersBlack: b.prisonersBlack,
prisonersWhite: b.prisonersWhite,
}
if b.ko != nil {
cpy.ko = &koLock{
Pos: b.ko.Pos,
Color: b.ko.Color,
}
}
copy(cpy.fieldSequencesBlack, b.fieldSequencesBlack)
copy(cpy.fieldSequencesWhite, b.fieldSequencesWhite)
// Copy .fields in a seperate loop first. The next loop, in which we set .actionOnNext{Black,White}Move
// depends upon correcty and already completely set .fields. Remember to copy each group only once!
copiedGroups := make(map[*Group]bool)
for i := 0; i < l; i++ {
grp := b.fields[i]
_, present := copiedGroups[grp]
if !present && grp != nil {
gcpy := grp.Copy()
last := gcpy.Fields.Last()
for it := gcpy.Fields.First(); it != last; it = it.Next() {
cpy.fields[it.Value()] = gcpy
}
// remember that we already copied grp
copiedGroups[grp] = true
}
}
for i := 0; i < l; i++ {
// copy .actionOnNextBlackMove and adjust its context
if f := b.actionOnNextBlackMove[i]; f != nil {
cpy.actionOnNextBlackMove[i] = NewActionFunc(cpy, nil, f.f)
_, cpy.actionOnNextBlackMove[i].context = cpy.getEnvironmentAndContext(i, Black)
}
// copy .actionOnNextWhiteMove and adjust its context
if f := b.actionOnNextWhiteMove[i]; f != nil {
cpy.actionOnNextWhiteMove[i] = NewActionFunc(cpy, nil, f.f)
_, cpy.actionOnNextWhiteMove[i].context = cpy.getEnvironmentAndContext(i, White)
}
}
return cpy
}
示例15: ReadDiploCsvFilesIfNew
func (m *TksManager) ReadDiploCsvFilesIfNew() error {
standardDiploFilename := "/home/dys/chrall/Public_Diplomatie.txt"
trollDiploFilename := "/home/dys/chrall/Diplodotrolls.csv"
mustRead := false
if m.lastDiploFileRead > 0 {
fi, err := os.Stat(standardDiploFilename)
if err != nil {
return err
}
if !fi.IsRegular() {
return errors.New("TksManager : Fichier " + standardDiploFilename + " introuvable ou anormal")
}
mustRead = fi.Mtime_ns > m.lastDiploFileRead*1000000000
}
if !mustRead {
fi, err := os.Stat(trollDiploFilename)
if err != nil {
return err
}
if !fi.IsRegular() {
return errors.New("TksManager : Fichier " + trollDiploFilename + " introuvable ou anormal")
}
mustRead = fi.Mtime_ns > m.lastDiploFileRead*1000000000
fmt.Printf("mustRead trollDiploFile = %v \n", mustRead)
}
if !mustRead {
return nil
}
g := NewDiploGraph()
f, err := os.Open(standardDiploFilename)
if err != nil {
return err
}
defer f.Close()
r := bufio.NewReader(f)
err = g.ReadDiploGraph(r, true, false)
if err != nil {
return err
}
f, err = os.Open(trollDiploFilename)
if err != nil {
return err
}
defer f.Close()
r = bufio.NewReader(f)
err = g.ReadDiploGraph(r, false, true)
if err != nil {
return err
}
m.lastDiploFileRead, _, _ = os.Time()
fmt.Println("TksManager : Fichiers de diplo lus")
m.Diplo = g
return nil
}