# Script For Converting To/From UNIX Time

I wrote an intuitive command line script for converting UNIX time to human-readable format and vice versa.

When I need to convert UNIX time, a quick [Google search](https://bfy.tw/RIvy) will yield solutions like this:

```bash
# Works on Mac OS but not Linux
date -r 1624032013

# Works on Linux but not Mac OS
date -d @1624032013

# Get current time UNIX timestamp
date +%s
```

I find "-r", "-d", "+%s" hard to remember. So I wrote a PHP script to simplify it. Save it as `/usr/bin/unixtime` and this is how I use it:

```bash
# Get current UNIX timestamp
unixtime

# Covert to UNIX time
unixtime "2021-12-24 23:59:59"

# Convert UNIX time to human readable time
unixtime 1624032013

# Get hints on how to use this script
unixtime help
```

Source code:

%[https://gist.github.com/hongster/cd462d11c491eef75c0b8dcd3768fa8d]
