Skip to content

Instantly share code, notes, and snippets.

@piaoger
Last active May 11, 2017 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piaoger/1a1cc29fa9fe95695282e2f5c57ec221 to your computer and use it in GitHub Desktop.
Save piaoger/1a1cc29fa9fe95695282e2f5c57ec221 to your computer and use it in GitHub Desktop.
get/set filetime in golang
import (
"os"
"syscall"
"time"
)
func statTimes(name string) (atime, mtime, ctime time.Time, err error) {
fi, err := os.Stat(name)
if err != nil {
return
}
mtime = fi.ModTime()
stat := fi.Sys().(*syscall.Stat_t)
atime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
ctime = time.Unix(int64(stat.Ctim.Sec), int64(stat.Ctim.Nsec))
return
}
func chTimes(name string, atime time.Time, mtime time.Time) {
os.Chtimes(name, atime, mtime)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment