askvity

What is the Format for API Date?

Published in API Data Formats 2 mins read

The common format for API dates is yyyy-MM-ddTHH:mm:ss.SSS+/-HH:mm or yyyy-MM-ddTHH:mm:ss. Let's break this down:

Here's a detailed explanation of the typical date and time format used in APIs:

  • yyyy: Represents the year in four digits (e.g., 2024).
  • MM: Represents the month in two digits (01 for January, 12 for December).
  • dd: Represents the day of the month in two digits (01 to 31).
  • T: A separator between the date and time components. It's always "T".
  • HH: Represents the hour in 24-hour format (00 to 23).
  • mm: Represents the minute (00 to 59).
  • ss: Represents the second (00 to 59).
  • .SSS: Represents milliseconds (optional, but common for high precision)
  • +/-HH:mm: Represents the time zone offset from Coordinated Universal Time (UTC). "+" indicates ahead of UTC, and "-" indicates behind UTC. HH represents the hours, and mm represents the minutes. For example, "-05:00" indicates Eastern Standard Time (EST). Z can be used to designate UTC time (+00:00 offset).

Examples:

  • 2024-01-20T14:30:00 (January 20, 2024, at 2:30 PM UTC)
  • 2024-01-20T14:30:00.123Z (January 20, 2024, at 2:30:00.123 PM UTC)
  • 2024-01-20T09:30:00-05:00 (January 20, 2024, at 9:30 AM EST)
  • 2024-12-31T23:59:59.999+00:00 (December 31, 2024, at 11:59:59.999 PM UTC)

This format is a profile of the ISO 8601 standard, which is widely used for representing dates and times in a standardized way. It's designed to be unambiguous and easily parsable by computers. While many APIs use this standard, always refer to the specific API's documentation to confirm the precise format they expect.

Related Articles