Skip to content

Instantly share code, notes, and snippets.

@micahredding
Created December 1, 2013 17:08
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 micahredding/7736838 to your computer and use it in GitHub Desktop.
Save micahredding/7736838 to your computer and use it in GitHub Desktop.
Go Function to Return MacOS X created time (birthtime)
package main
import (
"fmt"
"log"
"os"
"syscall"
"time"
)
func GetCreatedTime(file string) (crtime time.Time) {
f, err := os.Open(file)
defer f.Close()
if err != nil {
log.Fatal(err)
}
// More details using the syscall package
var s syscall.Stat_t
// Get the file descriptor
fd := int(f.Fd())
err = syscall.Fstat(fd, &s)
if err != nil {
log.Fatal(err)
}
return time.Unix(s.Birthtimespec.Unix())
}
func main() {
crtime := GetCreatedTime("test.go")
fmt.Printf(" birth: %s\n ", crtime)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment