find the creation date of a json file in go

To find the creation date of a JSON file in Go, we need to use the os.Stat function which returns a os.FileInfo object. This object includes the modifcation time of the file. Here's an example code snippet:

main.go
package main

import (
    "fmt"
    "os"
)

func main() {
    file, err := os.Stat("example.json")
    if err != nil {
        fmt.Println(err)
        return
    }

    fmt.Println("Creation Time:", file.ModTime())
}
219 chars
17 lines

In this example, we use the os.Stat function to get the os.FileInfo object that contains details about the file. Then we use the ModTime method of this object to get the modification time of the file. This modification time will be the creation time if the file has not been modified since it was created.

gistlibby LogSnag