PHP Classes

File: src/utils/date-formatter.js

Recommend this page to a friend!
  Classes of Maniruzzaman Akash   WP Emailer   src/utils/date-formatter.js   Download  
File: src/utils/date-formatter.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: WP Emailer
Allow WordPress users to configure email settings
Author: By
Last change:
Date: 1 year ago
Size: 681 bytes
 

Contents

Class file image Download
/** * Format a date timestamp to human readable time string. * * @param {Number} timestamp Timestamp number. * @param {Boolean} showHourMinute Is show hour-minute or not. * * @returns Formatted date string. */ export const formatDate = (timestamp, showHourMinute = false) => { const dateString = new Date(timestamp).toString(); // eg: Tue Jan 20 1970 12:57:14 GMT+0600 // We'll break this --> Tue Jan 20 1970 12:57:14 let date = `${dateString.substring(8, 10)} ${dateString.substring(4, 7)} ${dateString.substring(11, 15)}`; // 20 Jan 1970 if (showHourMinute) { date += ` at ${dateString.substring(16, 21)}`; // at 12:57 } return date; };