Datetime usage

List of status codes from API responses and their meaning

Date and time usage with eLabAPI

When using the eLabAPI, there might be moments when you want to use a date or time in your request. This document will explain how to use date and time in your request.

Date and time format

The eLabAPI uses the ISO 8601 date and time format. This format is a standard for date and time representation. The format is as follows:

YYYY-MM-DD HH:MM:SS

Where:

  • YYYY is the year
  • MM is the month
  • DD is the day
  • HH is the hour
  • MM is the minute
  • SS is the second

UTC time

The eLabAPI uses UTC time. This means that all date and time values are in Coordinated Universal Time (UTC). When you want to use a date and time in your request, you MUST use the UTC time. These values will be converted to the user-set time zone in the eLab environment.

To ensure that the date and time that you use in your request is in UTC time, you can use code like the following example to get the current date and time in UTC time:

const moment = require('moment-timezone');

function getCurrentTime(timezone) {
    try {
        // Get the current time in the specified timezone
        const time = moment().tz(timezone);

        // Format the time
        const timeStr = time.format('YYYY-MM-DD HH:mm:ss');

        console.log(`${timezone} time: ${timeStr}`);
        return timeStr;
    } catch (error) {
        console.log("Invalid timezone");
        return null;
    }
}

// Set timezone to 'UTC' to get respective time
const timezone = 'UTC';

// Get the current time in the specified timezone
const currentTime = getCurrentTime(timezone);