Skip to content

Instantly share code, notes, and snippets.

@danielgwood
danielgwood / gist:1510463
Created December 22, 2011 14:23
Human formatted time between dates (JavaScript)
/**
* Given two dates (or one date and assume "now" for the second), convert this to
* a human-readable string, like "2 months".
*
* I use this to put "3 months ago" strings into plugins. My use case has the date
* coming in as a seconds-only UNIX epoch, so the params are expected at this.
*
* @param time1 integer Number of seconds since UNIX epoch
* @param time2 integer Number of seconds since UNIX epoch
* @return string