Skip to content

Instantly share code, notes, and snippets.

@js2me
Created April 18, 2019 09:57
Show Gist options
  • Save js2me/ff281c18c8e25e8741e6fa08a845e5f0 to your computer and use it in GitHub Desktop.
Save js2me/ff281c18c8e25e8741e6fa08a845e5f0 to your computer and use it in GitHub Desktop.
convert unix time to date
/**
* @name unixTimeToDate
*
* @param {number} unixTimeStamp
* @param {boolean} fromNow = add current time to unix timestamp
*
* @returns {Date} JavaScript Date type
*/
export const unixTimeToDate = (unixTimeStamp, fromNow = false) =>
new Date((fromNow ? Date.now() : 0) + unixTimeStamp * 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment