0

I'm designing a JSON format for my RESTful service, and want to find a good way to express relative time.

For example: 1 minutes, 2 hours, 3 days, 4 weeks, 5 years

And come up: {"interval": 1, "unit": "day"}, are there better ways to express this?

yjshen
  • 6,583
  • 3
  • 31
  • 40
  • Don't know about common practice at this point, but in my experience it's best to "normalize" time and date values (for example to an UNIX timestamp) and do the formatting in the presentation part. So I'd note the interval down as for example the number of seconds from the fixed origin in time, say `{ "interval" : 123456 }`. That number can be computed to just about any output, for example "X seconds ago", "X months Y day ago" and so forth. – Henning Kockerbeck May 07 '15 at 09:02

1 Answers1

0

you can format your json like this...

{
"interval": 
    {
        "min": 30,
        "hr": 10,
        "day": 12,
        "week": 2,
        "month": 3,
        "year": 1
    }    
}

datatype of each key is int ..and its enough

Angad Tiwari
  • 1,738
  • 1
  • 12
  • 23