Convert Timestamp

Convert Timestamp to Readable Date

Build a script to convert Unix timestamp (in both seconds and milliseconds) to human-readable date.

Getting Started

Step 1

Download day.min.js (opens in a new tab) and put the file in packages folder.

Step 2

Create a script file in the script folder with the following code.

@okjson.schemaVersion 1 Convert Timestamp
@okjson.description Convert Unix timestamp to human-readable date.
@okjson.icon clock
@okjson.preprocessInput no
@okjson.openResultInNewWindow no OK JSON
function main(timestamp) {
  const number = parseFloat(timestamp);
  if (isNaN(number)) {
      'Input Error',
      `“${timestamp}” cannot be converted to number.`
    return '';
  let dayjsObject = null;
  if (timestamp.length === 10) {
    dayjsObject = dayjs.unix(number);
  } else if (timestamp.length === 13) {
    dayjsObject = dayjs(number);
  } else {
    $alert.error('Input Error', `“${timestamp}” is not a valid timestamp.`);
    return '';
  const formatted = dayjsObject.format('YYYY-MM-DD HH:mm:ss');
  $alert.success(`Timestamp: ${timestamp}`, formatted);
  return '';

Example Timestamp for Testing

Monday, May 1, 2023 12:00:00 AM (GMT)