ut is a command line tool to handle a unix timestamp.
There is a number of times to generate/parse unix timestamps.
I think date
command exists to handle these situations. But there are a few problems that they are small, but vital for me.
- cannot use same options between macOS and Linux.
- hard to remember usage. (it might be happen because of above problem.)
That's why I made a new command line tool ut-cli
.
I hope ut-cli works well when developers need to use the command which requires timestamps like aws-cli.
Search logs from specific time period. ``` bash
$ aws logs filter-log-events \
--log-group-name
If you have rust toolchain, ut-cli can be installed with cargo.
bash
$ cargo install ut-cli
or clone the repository and build it.
bash
$ git clone https://github.com/yoshihitoh/ut-cli
$ cd ut-cli
$ cargo build --release
$ ./target/release/ut --version
ut 0.1.7
Also there are pre-built binary for Linux, macOS and Windows. See releases.
``` bash ut-cli 0.1.7 yoshihitoh yoshihito.arih@gmail.com A command line tool to handle unix timestamp.
USAGE:
ut [FLAGS] [OPTIONS]
FLAGS: -u, --utc Use utc timezone. -h, --help Prints help information -V, --version Prints version information
OPTIONS:
-o, --offset
SUBCOMMANDS: generate Generate unix timestamp with given options. help Prints this message or the help of the given subcommand(s) parse Parse a unix timestamp and print it in human readable format. ```
You can set options via envrionment variables.
| name | equiv option | example |:------------ :|:--------------:|:----------- | UTOFFSET | -o/--offset | 09:00 | UTPRECISION | -p/--precision | millisecond | UTDATETIMEFORMAT | - | %Y-%m-%d %H:%M
UTDATETIMEFORMAT follows chrono's datetime specifiers. See the document for details.
```bash
$ export UTOFFSET='09:00' # Use JST(+9). $ export UTPRECISION=millisecond # Use timestamps in milliseconds.
$ ut g 1588059756238
$ echo 1588059756238 | ut p 2020-04-28 16:42:36.238 (+09:00)
$ export UTDATETIMEFORMAT="%m/%d/%Y" $ echo 1588059756238 | ut --offset=-7 p 04/28/2020 ```
is equivalent to
bash
$ ut -o '09:00' -p millisecond p $(ut -o '09:00' -p millisecond g)
There are two subcommands available for now. - generate(g) - parse(p)
Generate a unix timestamp of the midnight of today. ``` bash $ ut generate -b today 1560870000
-p
option to show it in millisecond.$ ut -p ms generate -b today 1560870000000 ```
You can specify time deltas with -d
option.
``` bash
$ ut g -b today -d 3day -d 12hour -d 30minute 1561174200
$ ut g -b today -d 3d -d 12h -d 30min 1561174200
$ ut g -d 1min 1561174200 1561174260 # 1min(=60second) difference. ```
Parse a unix timestamp and print it in human readable format. ``` bash $ ut p $(ut g -b today) 2019-06-19 00:00:00 (+09:00)
$ ut -p ms p $(ut -p ms g -b today -d 11h -d 22min -d 33s -d 444ms) 2019-06-19 11:22:33.444 (+09:00) ```
If you don't set timezone options, ut command uses local timezone.
In Japan(UTC+9): ``` bash $ ut g --ymd 2019-06-24 1561302000
$ ut p 1561302000 2019-06-24 00:00:00 (+09:00) ```
You can use -u
or --utc
option to use UTC timezone.
bash
$ ut --utc p 1561302000
2019-06-23 15:00:00 (UTC)
You can use fixed offset timezone on any environment. ``` bash
$ ut -o -8 g --ymd 2019-06-24 1561363200
$ ut -o -8 p 1561363200 2019-06-24 00:00:00 (-08:00)
$ ut -o 0 p 1561363200 2019-06-24 08:00:00 (+00:00) ```