41 lines
778 B
Go
41 lines
778 B
Go
|
//
|
||
|
// file_time.go
|
||
|
// Copyright (C) 2022 tiglog <me@tiglog.com>
|
||
|
//
|
||
|
// Distributed under terms of the MIT license.
|
||
|
//
|
||
|
|
||
|
package gfile
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
// MTime returns the modification time of file given by `path` in second.
|
||
|
func MTime(path string) time.Time {
|
||
|
s, e := os.Stat(path)
|
||
|
if e != nil {
|
||
|
return time.Time{}
|
||
|
}
|
||
|
return s.ModTime()
|
||
|
}
|
||
|
|
||
|
// MTimestamp returns the modification time of file given by `path` in second.
|
||
|
func MTimestamp(path string) int64 {
|
||
|
mtime := MTime(path)
|
||
|
if mtime.IsZero() {
|
||
|
return -1
|
||
|
}
|
||
|
return mtime.Unix()
|
||
|
}
|
||
|
|
||
|
// MTimestampMilli returns the modification time of file given by `path` in millisecond.
|
||
|
func MTimestampMilli(path string) int64 {
|
||
|
mtime := MTime(path)
|
||
|
if mtime.IsZero() {
|
||
|
return -1
|
||
|
}
|
||
|
return mtime.UnixNano() / 1000000
|
||
|
}
|