-2

I got value - 20927, and its have to be in this format - 14d 12h 47m

I tried do math by myself but didn't found any solutions.

J.bow
  • 1
  • 3
  • What is this `20927`? – Ele Mar 09 '18 at 03:45
  • 1
    Please take the [tour](https://stackoverflow.com/tour) and read through the [help center](https://stackoverflow.com/help), in particular *[How do I ask a good question?](https://stackoverflow.com/help/how-to-ask)* Do your research, [search](https://stackoverflow.com/help/searching) for related topics on SO, and give it a go. If you get stuck and can't get unstuck after doing more research and searching, post a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) of your attempt and say specifically where you're stuck. People will be glad to help. – Ele Mar 09 '18 at 03:45
  • https://stackoverflow.com/questions/36098913/convert-seconds-to-days-hours-minutes-and-seconds I think this is the solution you're after. – Paul McLoughlin Mar 09 '18 at 03:49
  • 20927 is value in minutes – J.bow Mar 09 '18 at 03:50
  • oops misspelling in title i mean minutes not seconds. sorry – J.bow Mar 09 '18 at 03:54

2 Answers2

2

You could use moment.js

const duration = moment.duration(20927, 'minutes')
const durationString = duration.days() + 'd ' + duration.hours() + 'h ' + duration.minutes() + 'm'
console.log(durationString) //"14d 12h 47m"
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.21.0/moment.min.js"></script>
Codeseer
  • 94
  • 4
  • An answer should not require a library that isn't tagged or asked for in the OP. This has been answered before. – RobG Mar 09 '18 at 04:16
  • Why 90% community in this site so edgy? How can i tag library if i didn't even know how to solve my problem? – J.bow Mar 09 '18 at 04:17
  • @J.bow—libraries can be suggested in comments and answers, but they should not be the sole basis for an answer. Seconds can be converted to d:h:m:s in one line of code, there's no need for a 4,000 line, 56kB library. – RobG Mar 09 '18 at 04:27
  • @RobG definitely agree importing library unnecessarily is not good. But if OP use case is manipulating dates heavily a utility library like moment.js can save a lot of developer time. (Which can be just as important as performance in many cases.) Also question is tagged as node.js so I assumed library size was not a big factor since it won't be used in the browser. – Codeseer Mar 09 '18 at 04:39
-1

Try moment.js:

moment(0).add(20927, 'm').format('DD[h] hh[h] MM[m]')
guijob
  • 4,413
  • 3
  • 20
  • 39
  • thank you i will try it as well :) – J.bow Mar 09 '18 at 04:10
  • An answer should not require a library that isn't tagged or asked for in the OP. This has been answered before. – RobG Mar 09 '18 at 04:16
  • 1
    Could you point me any resources which enforces your argument? Seems pretty ok to me to suggest a library once OP doesn't request for a pure js solution – guijob Mar 09 '18 at 04:28