Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Generate times (as strings) for every 10 minutes from current time in JavaScript

$
0
0

In my scenario, I am trying to generate a time from current time to previous 60 min, each numbers 10 minutes difference. For example my current time is 11 then I want to generate like this: 10.30, 10.40, 10.50, 11.00.

How to achieve this current by using below code, I am getting reverse array current should be first index. How to achieve like this: 10.30, 10.40, 10.50, 11.00.

function addMinutes(date, minutes) {    return new Date(date.getTime() + minutes*60000);}function () {    var d = new Date();    var result = "";    for (var idx = 0; idx < 6; idx++)    {        var m = (((d.getMinutes() + 7.5)/15 | 0) * 15) % 60;        var h = ((((d.getMinutes()/105) + .5) | 0) + d.getHours()) % 24;        d = new Date(d.getYear(), d.getMonth(), d.getDay(), h, m, 0, 0);        if (idx > 0) result += ", ";        result += ("0" + h).slice(-2) +":" + ("0" + m).slice(-2);        d = addMinutes(d, -15);    }    $(".answer").text("Time: " + result);});

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>