This repository comes with a couple of implementations of the base algorithm in
different languages. You can use any by simply dropping the logic into your
source code.
Node.JS
You can install the javascript version of this with
npm install human-time
and use it like
var human = require('human-time');human(754);// => "12 minutes ago"human(new Date(Date.now() + 5 * 1000))// => "5 seconds from now"human(new Date(Date.now() - 5 * 1000))// => "5 seconds ago"
Example (C)
compile
make
run
$ ./human 651 minute$ ./human 60010 minutes
With the C example, you can optionally pass -s to get a suffix
$ ./human 5748315 hours$ ./human -s 5748315 hours from now$ ./human -s -5748315 hours ago