Skip to content

Function: getTimestamp()

ts
function getTimestamp(props?: GetTimestampProps): string;

Defined in: src/utils/getTimestamp.ts:302

Generate a formatted timestamp string.

By default the timestamp uses UTC. Set useLocalTimezone to true to use the system's local timezone, or pass a specific timezone (IANA identifier or abbreviation like 'IST', 'CET').

Parameters

ParameterTypeDescription
propsGetTimestampPropsOptions to control which date parts to include.

Returns

string

The formatted timestamp string.

Examples

ts
// Default usage with current UTC date
const ts = getTimestamp(); // "2024-09-26-15-30-45"
ts
// Custom separator
const ts = getTimestamp({ separator: '/' }); // "2024/09/26/15/30/45"
ts
// Only year, month, and day
const ts = getTimestamp({
  date: new Date('2023-12-01T08:22:33Z'),
  includeHours: false,
  includeMinutes: false,
  includeSeconds: false,
}); // "2023-12-01"
ts
// Only hours, minutes, and seconds
const ts = getTimestamp({
  date: new Date('2023-12-01T08:22:33Z'),
  includeYear: false,
  includeMonth: false,
  includeDay: false,
}); // "08-22-33"
ts
// Timezone abbreviation
const ts = getTimestamp({
  date: new Date('2024-09-26T15:30:45Z'),
  timezone: 'IST',
}); // "2024-09-26-21-00-45"

Matterway Assistant SDK Documentation