github.com/wangyougui/gf/v2@v2.6.5/os/gfile/gfile_time.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). 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/wangyougui/gf.
     6  
     7  package gfile
     8  
     9  import (
    10  	"os"
    11  	"time"
    12  )
    13  
    14  // MTime returns the modification time of file given by `path` in second.
    15  func MTime(path string) time.Time {
    16  	s, e := os.Stat(path)
    17  	if e != nil {
    18  		return time.Time{}
    19  	}
    20  	return s.ModTime()
    21  }
    22  
    23  // MTimestamp returns the modification time of file given by `path` in second.
    24  func MTimestamp(path string) int64 {
    25  	mtime := MTime(path)
    26  	if mtime.IsZero() {
    27  		return -1
    28  	}
    29  	return mtime.Unix()
    30  }
    31  
    32  // MTimestampMilli returns the modification time of file given by `path` in millisecond.
    33  func MTimestampMilli(path string) int64 {
    34  	mtime := MTime(path)
    35  	if mtime.IsZero() {
    36  		return -1
    37  	}
    38  	return mtime.UnixNano() / 1000000
    39  }