Home > other >  Convert time json to minutes and seconds
Convert time json to minutes and seconds

Time:02-12

I have this json:

"result": {
  "status": "passed",
  "duration": 255561500
}

I would like to convert the number (255561500) in attribute duration to minutes and seconds. And what format is this number?

CodePudding user response:

Choose whichever you prefer here https://gist.github.com/shunchu/3175001

CodePudding user response:

You can use Time.at to convert a value in date type. This is a basic example as I do it.

strJson = '{"result": { "status": "passed", "duration": 255561500 }}'
yourJson = JSON.parse(strJson)
duration = yourJson['result']['duration']
valueInDateFormat =Time.at(duration).utc.strftime("%H:%M:%S")
  • Related