A timestamp to readable string or timestamp to date converter is a function that takes a timestamp as input and returns a human-readable date string in a specific format (such as "DayName, MonthName Date, Year"). This is useful for presenting timestamps in a more user-friendly way, and can be customized to match a variety of date and time formats.
Installation
npm install timestamp-to-string
Usage
constconvert=require('timestamp-to-string')// Convert timestamp to dateconsttimestamp=1614131200constdate=convert.toDate(timestamp,'YYYYMMDD')console.log(date)// 2021-02-25
constconvert=require('timestamp-to-string')// Convert timestamp to readable stringconsttimestamp=1614131200constdate=convert.now('DDDMMMDDYYYY')console.log(date)// Friday, February 26, 2021
Options
toDate(timestamp, format)
Parameter
Type
Description
timestamp
Number
Timestamp to be converted to date.
format
String
Format of the date to be returned. See format for more information
now(format)
Parameter
Type
Description
format
String
Format of the date to be returned. See format for more information
toTime(timestamp, format)
Parameter
Type
Description
timestamp
Number
Timestamp to be converted to time.
format
String
Format of the time to be returned. See format for more information