moment.js - конвертируем секунды в минуты и часы
Сейчас использую такое решение:
Код:
$("#tileList .wtime").html(function(index, value) {В переменной value находятся секунды. Если число не превышает 60, все ок. Но если там допустим 68. По идеи moment должен показывать 00:01:08. Но он пишет Invalid date, помогите пожалуйста решить эту проблему ![]() |
Пришла в голову идея все перевести в миллисекунды. То есть умножить на 1000.
Код:
$("#tileList .wtime").html(function(index, value) {![]() |
Rise,
не могли бы вы подсказать решение, если вам не трудно. документация мне не помогла, проблема таже что у ТС, лишние часы, как убрать смещение часового пояса средствами moment.js |
moment.js секунды в часы
Rise,
типа макета ...
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://momentjs.com/downloads/moment.js">
</script>
<script>
$(function(){ moment.locale('ru');
$("#tileList .wtime").html(function(index, value) {
return moment.unix(value).format("HH:mm:ss");
});
})
</script>
</head>
<body>
<form action="" id="tileList">
<p class="wtime">71</p>
<p class="wtime">72</p>
<p class="wtime">3</p>
<p class="wtime">4</p>
<p class="wtime">5</p>
<p class="wtime">6</p>
<p class="wtime">7</p>
<p class="wtime">8</p>
<p class="wtime">9</p>
<p class="wtime">10</p>
<p class="wtime">11</p>
<p class="wtime">12</p>
<p class="wtime">13</p>
<p class="wtime">14</p>
<p class="wtime">15</p>
<p class="wtime">16</p>
<p class="wtime">17</p>
<p class="wtime">18</p>
<p class="wtime">19</p>
<p class="wtime">20</p>
</form>
</body>
</html>
|
рони,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://momentjs.com/downloads/moment.js">
</script>
<script>
$(function(){ moment.locale('ru');
$("#tileList .wtime").html(function(index, value) {
return moment.unix(value).utc().format("HH:mm:ss");
});
})
</script>
</head>
<body>
<form action="" id="tileList">
<p class="wtime">71</p>
<p class="wtime">72</p>
<p class="wtime">3</p>
<p class="wtime">4</p>
<p class="wtime">5</p>
<p class="wtime">6</p>
<p class="wtime">7</p>
<p class="wtime">8</p>
<p class="wtime">9</p>
<p class="wtime">10</p>
<p class="wtime">11</p>
<p class="wtime">12</p>
<p class="wtime">13</p>
<p class="wtime">14</p>
<p class="wtime">15</p>
<p class="wtime">16</p>
<p class="wtime">17</p>
<p class="wtime">18</p>
<p class="wtime">19</p>
<p class="wtime">20</p>
</form>
</body>
</html>
|
destus,
ок спасибо, сам не в то место я ставил |
| Часовой пояс GMT +3, время: 07:57. |