Table of Contents
Description
The formatTimestamp
function formats a given timestamp into a specified format or locale string.
Basic Usage
import formatTimestamp from '../../src/utils/formatTimestamp.js';
const timestamp = Date.now();
console.log(formatTimestamp(timestamp, 'YYYY-MM-DD hh:mm:ss')); // Example output: 2023-10-05 14:48:32
console.log(formatTimestamp(timestamp)); // Example output: 10/5/2023, 2:48:32 PM if the browser locale is en-US
JavaScript Reference
Function
formatTimestamp(timestamp, format, forceLocale)
Parameters
timestamp
: number - The timestamp to format.format
: string (optional) - The format string. If not provided, the locale string is returned.forceLocale
: string (optional) - The locale to use for formatting.
Returns
string
- The formatted timestamp.