Ап
Как преобразовать секунды в формат времени чч:мм:cc ?
-
@ElTigre said in Как преобразовать секунды в формат времени чч:мм:cc ?:
1081
var date = new Date(null); date.setSeconds(1081); // specify value for SECONDS here var result = date.toISOString().substr(11, 8); log(result);or as one line of code >
log(new Date(1081 * 1000).toISOString().substr(11, 8)) -
First of all, the proper way to say "thank you very much, it works)"
is to UPVOTE the post.Secondly, its not clear what you actually want to achieve from
your question. But Ill give you some solutions that might work
for you.If you just want to extract mm:ss from above example, you can do it
simply by removing first 3 chars from result like this >log(new Date(1091 * 1000).toISOString().substr(11, 8)).substring(3);But if you need exact number of minutes and seconds from seconds
its a different thing and sometimes it cant be output as mm:ss because
there could be 100+ minutes in given seconds variable (3 or more
digits amd "mm" format means max 2 digits with leading 0 for values
smaller than 10).So to calculate any number of minutes and seconds from large number
of seconds you need to do as follows >totalSeconds = 33649; minutes = Math.floor(totalSeconds / 60); seconds = totalSeconds % 60; log("minutes: " + minutes); log("seconds: " + seconds); -
M Moderator moved this topic from Off topic on
-
-
-
BAS в zelenka.guru
Moved Other -
-