Time formatting function

implement the formatTime (dateStr, format) method, and the parameter dateStr is date.toISOString ()

parameter format supports" YYYY","MM","M","DD","D","hh","h","mm","m","ss","s"

reference example:
enter formatTime ("2016-08-29T02 DD DD day")

output: August 29, 2016

Nov.15,2021

moment can fulfill your needs
moment ('2016-08-29T02 DD 03.863Z'). Format (' YYY').


conventional scheme , if it is too big, consider DAYJS .


/**
 * 
 *
 * @param {String, Number} timestamp ()
 * @param {String} format ()
 *    format='YYYY-MM-DD'
 *    format='MM/DD hh:mm'
 * @returns {String} default return YYYY/MM/DD hh:mm:ss
 */
function formatTimestamp(timestamp, format = 'YYYY/MM/DD hh:mm:ss') {
  let time = Number.parseInt(timestamp, 10);
  let date = new Date(time);

  let year = date.getFullYear();
  let month = date.getMonth() + 1;
  let day = date.getDate();
  let hour = date.getHours();
  let minute = date.getMinutes();
  let second = date.getSeconds();

  month = month > 9 ? month : `0${month}`;
  day = day > 9 ? day : `0${day}`;
  hour = hour > 9 ? hour : `0${hour}`;
  minute = minute > 9 ? minute : `0${minute}`;
  second = second > 9 ? second : `0${second}`;

  return format
    .replace('YYYY', year)
    .replace('MM', month)
    .replace('DD', day)
    .replace('hh', hour)
    .replace('mm', minute)
    .replace('ss', second);
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3bf19-2c2c9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3bf19-2c2c9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?