MomentJS & Unix Epoch

Suppose we are working on a project where you have timestamps as Unix Epoch, and we need to do a variety of things with that timestamp. Here are some things you may find helpful.

// Create a unix epoch
let epoch = moment.unix(); // Always returns an Int

// If epoch is a String instead of an Int, you're gonna have a bad time
epoch = !isNaN(parseInt(epoch)) ? parseInt(epoch, 10) : null; // parseInt base 10

if(epoch != null){
  // Convert epoch to moment object
  let momentObject = moment.unix(epoch))

  // now use that moment object to convert time to custom format MONTH/DAY/YR HR:MIN:SEC.
  let monthDayYear = momentObject.format('MM/DD/YYYY HH:mm:ss')

  // Or consider it in one line 
  let full = moment.unix(epoch).format('MM/DD/YYYY HH:mm:ss')\
  console.log('epoch is null')