Search code examples
javarestdateurlodata

accepted way to send date and time with timezone parameter in URL


In OData/REST service I want to allow date parameters startDate and endDate that marks the daterange of data returned. Example:

GET /events?startDate=XXX&endDate=YYY

Questions:

  1. What are the standard formats for date and time in URL?
  2. Should I consider adding a timezone (or UTC offset)? What is expected if timezone was not added?

Solution

  • See World Wide Web Consortium (W3C) date formats, you can send in format YYYY-MM-DDThh:mm:ss.sTZD

    e.g 1997-07-16T19:20:30.45+01:00

    Without seconds:

    YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)

    1. Default time zone is US Eastern Standard Time:

    1994-11-05T08:15:30-05:00 corresponds to November 5, 1994, 8:15:30 am, US Eastern Standard Time.

    1994-11-05T13:15:30Z corresponds to the same instant.