Skip to content

Time Information

The /time endpoint allows you to retrieve time information based on various parameters. You can get the current time or a random time between a specified range, in different formats and time zones.

Parameters

ParameterRequiredDescription
typeNolive (default) for current time, random for random time
startNoStart date for random range (format: YYYY-MM-DD)
endNoEnd date for random range (format: YYYY-MM-DD)
formatNoResponse format (see options below)
timezoneNoTime zone to use (see options below)

Format Options

FormatDescription
isoISO 8601 format (default)
timestampUnix timestamp
localeLocal format
dateDate in MM/DD/YYYY format
timeTime in HH:MM:SS format
yearYear only
monthMonth only
dayDay only
hourHour only
minuteMinutes only
secondSeconds only
msMilliseconds only
dayOfWeekDay of the week (0-6)
dayOfYearDay of the year (1-365/366)
weekNumberWeek number
timezoneTime zone name
timezoneOffsetTime zone offset

Timezone Options

TimezoneDescription
UTCCoordinated Universal Time (default)
Europe/ParisParis time zone
America/New_YorkNew York time zone
Asia/TokyoTokyo time zone
Australia/SydneySydney time zone

Request Examples

Current Time (All Formats)

GET /v3/time
json
{
  "iso": "2000-01-01T12:00:00.000Z",
  "utc": "Sat, 01 Jan 2000 12:00:00 GMT",
  "timestamp": 946724400,
  "locale": "1/1/2000, 12:00:00 PM Coordinated Universal Time",
  "date": "3/3/2000",
  "time": "12:00:00 PM",
  "year": 2000,
  "month": 1,
  "day": 1,
  "hour": 12,
  "minute": 0,
  "second": 0,
  "ms": 0,
  "dayOfWeek": 6,
  "dayOfYear": 1,
  "weekNumber": 1,
  "timezone": "UTC",
  "timezoneOffset": 0
}

Random Time with Specific Format

bash
curl -X GET "https://api.sylvain.pro/v3/time?type=random&format=locale&timezone=America/New_York"
json
{
  "date": "7/28/2024, 5:06:52 AM Eastern Standard Time"
}

Error Handling

If parameters are invalid, the API will return an error:

Error MessageDescription
Please provide a valid type (?type={type})The type parameter is invalid
Please provide a valid start date (?start={YYYY-MM-DD})The start parameter is invalid
Please provide a valid end date (?end={YYYY-MM-DD})The end parameter is invalid
Please provide a valid format (?format={format})The format parameter is invalid
Please provide a valid timezone (?timezone={timezone})The timezone parameter is invalid