gfile_time.go 929 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2017-2018 gf Author(https://github.com/gogf/gf). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. package gfile
  7. import (
  8. "os"
  9. "time"
  10. )
  11. // MTime returns the modification time of file given by <path> in second.
  12. func MTime(path string) time.Time {
  13. s, e := os.Stat(path)
  14. if e != nil {
  15. return time.Time{}
  16. }
  17. return s.ModTime()
  18. }
  19. // MTimestamp returns the modification time of file given by <path> in second.
  20. func MTimestamp(path string) int64 {
  21. mtime := MTime(path)
  22. if mtime.IsZero() {
  23. return -1
  24. }
  25. return mtime.Unix()
  26. }
  27. // MTimestampMilli returns the modification time of file given by <path> in millisecond.
  28. func MTimestampMilli(path string) int64 {
  29. mtime := MTime(path)
  30. if mtime.IsZero() {
  31. return -1
  32. }
  33. return mtime.UnixNano() / 1000000
  34. }