2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2018-10-22 13:19:06 +08:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
2019-02-02 16:18:25 +08:00
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
2018-10-22 13:19:06 +08:00
|
|
|
|
|
|
|
package gfile
|
|
|
|
|
|
|
|
import (
|
2019-06-19 09:06:52 +08:00
|
|
|
"os"
|
2020-03-26 09:29:36 +08:00
|
|
|
"time"
|
2018-10-22 13:19:06 +08:00
|
|
|
)
|
|
|
|
|
2021-10-21 18:22:47 +08:00
|
|
|
// MTime returns the modification time of file given by `path` in second.
|
2020-03-26 09:29:36 +08:00
|
|
|
func MTime(path string) time.Time {
|
2019-06-19 09:06:52 +08:00
|
|
|
s, e := os.Stat(path)
|
|
|
|
if e != nil {
|
2020-03-26 09:29:36 +08:00
|
|
|
return time.Time{}
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2020-03-26 09:29:36 +08:00
|
|
|
return s.ModTime()
|
2018-10-22 13:19:06 +08:00
|
|
|
}
|
|
|
|
|
2021-10-21 18:22:47 +08:00
|
|
|
// MTimestamp returns the modification time of file given by `path` in second.
|
2020-03-26 09:29:36 +08:00
|
|
|
func MTimestamp(path string) int64 {
|
|
|
|
mtime := MTime(path)
|
|
|
|
if mtime.IsZero() {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
return mtime.Unix()
|
|
|
|
}
|
|
|
|
|
2021-10-21 18:22:47 +08:00
|
|
|
// MTimestampMilli returns the modification time of file given by `path` in millisecond.
|
2020-03-26 09:29:36 +08:00
|
|
|
func MTimestampMilli(path string) int64 {
|
|
|
|
mtime := MTime(path)
|
|
|
|
if mtime.IsZero() {
|
|
|
|
return -1
|
2019-06-19 09:06:52 +08:00
|
|
|
}
|
2020-03-26 09:29:36 +08:00
|
|
|
return mtime.UnixNano() / 1000000
|
2018-10-22 13:19:06 +08:00
|
|
|
}
|