2

I have an API written in Swagger 2.0 that says an entity has a property called when of type date-time:

properties:
  when:
    type: string
    format: date-time

I don't know how to parse the string. How should I expect the date-time format to looks like? I cannot find this in the Swagger 2.0 documentation

Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137
mat_boy
  • 12,998
  • 22
  • 72
  • 116

1 Answers1

3

As per the Open API 2.0 spec, the date-time should be defined by RFC3339.

For example:

  1. 2016-03-22T21:03:41
  2. 1985-04-12T23:20:50.52Z
  3. 1990-12-31T15:59:60-08:00

I don't know how to parse the string.

This would depend on the language you're using. In JavaScript, Date.parse(dateString) can easily parse the string. Or in Java, you can refer to Converting ISO 8601-compliant String to java.util.Date to know how to parse the date string.

Community
  • 1
  • 1
  • Ok, I mean, I know to to parse a String to Date in Java. I was wondering which format I should expect for the date. Now I know. Yeah, of course the one that implements the API can do a mistake. Then I cannot parse the response :) – mat_boy Mar 24 '16 at 08:04
  • 2
    RFC3339 dates require the time-offset component, so your example #1 does not comply. – Ken Geis Mar 09 '17 at 21:08