2017-11-10 18:16:38 +08:00
|
|
|
times
|
|
|
|
==========
|
|
|
|
|
|
|
|
[![GoDoc](https://godoc.org/github.com/djherbis/times?status.svg)](https://godoc.org/github.com/djherbis/times)
|
|
|
|
[![Release](https://img.shields.io/github/release/djherbis/times.svg)](https://github.com/djherbis/times/releases/latest)
|
|
|
|
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE.txt)
|
|
|
|
[![Build Status](https://travis-ci.org/djherbis/times.svg?branch=master)](https://travis-ci.org/djherbis/times)
|
|
|
|
[![Coverage Status](https://coveralls.io/repos/djherbis/times/badge.svg?branch=master)](https://coveralls.io/r/djherbis/times?branch=master)
|
|
|
|
[![Go Report Card](https://goreportcard.com/badge/github.com/djherbis/times)](https://goreportcard.com/report/github.com/djherbis/times)
|
2018-11-24 23:31:25 +08:00
|
|
|
[![Sourcegraph](https://sourcegraph.com/github.com/djherbis/times/-/badge.svg)](https://sourcegraph.com/github.com/djherbis/times?badge)
|
2017-11-10 18:16:38 +08:00
|
|
|
|
|
|
|
Usage
|
|
|
|
------------
|
|
|
|
File Times for #golang
|
|
|
|
|
|
|
|
Go has a hidden time functions for most platforms, this repo makes them accessible.
|
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
2019-02-09 20:50:35 +08:00
|
|
|
"gopkg.in/djherbis/times.v1"
|
2017-11-10 18:16:38 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
t, err := times.Stat("myfile")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println(t.AccessTime())
|
|
|
|
log.Println(t.ModTime())
|
|
|
|
|
|
|
|
if t.HasChangeTime() {
|
|
|
|
log.Println(t.ChangeTime())
|
|
|
|
}
|
|
|
|
|
|
|
|
if t.HasBirthTime() {
|
|
|
|
log.Println(t.BirthTime())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Supported Times
|
|
|
|
------------
|
2019-02-09 20:50:35 +08:00
|
|
|
| | windows | linux | solaris | dragonfly | nacl | freebsd | darwin | netbsd | openbsd | plan9 | js |
|
|
|
|
|:-----:|:-------:|:-----:|:-------:|:---------:|:------:|:-------:|:----:|:------:|:-------:|:-----:|:-----:|
|
|
|
|
| atime | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
|
|
|
| mtime | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
|
|
|
|
| ctime | ✓* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | ✓ |
|
|
|
|
| btime | ✓ | | | | | ✓ | ✓| ✓ | |
|
2017-11-10 18:16:38 +08:00
|
|
|
|
|
|
|
* Windows XP does not have ChangeTime so HasChangeTime = false,
|
|
|
|
however Vista onward does have ChangeTime so Timespec.HasChangeTime() will
|
|
|
|
only return false on those platforms when the syscall used to obtain them fails.
|
|
|
|
* Also note, Get(FileInfo) will now only return values available in FileInfo.Sys(), this means Stat() is required to get ChangeTime on Windows
|
|
|
|
|
|
|
|
Installation
|
|
|
|
------------
|
|
|
|
```sh
|
2019-02-09 20:50:35 +08:00
|
|
|
go get gopkg.in/djherbis/times.v1
|
2017-11-10 18:16:38 +08:00
|
|
|
```
|