Search code examples
javascripttimetimestamprecurring

How can I get recurring timestamp in JS?


I want to get recurring time in timestamp. For example, 17:00, 17:30, 18:00 and so on. Therefore, each day will have a different timestamp for this watch.

How can i do this?


Solution

  • It worked for me.

    // 24 hours format
    var array = [[07, 30, 0, 0], [07, 40, 0, 0], [07, 50, 0, 0], [23, 55, 0, 0]]
    
    // An array for storing timestamp
    var timestamp = [];
    
    var date = new Date();
    
    function getReccuringTimestamp(array) {
      for (var i = 0; i < array.length; i++) {
        let timeCalculation = Math.floor(date.setHours(...array[i]) / 1000);
        timestamp.push(timeCalculation);
      };
    };
    
    getReccuringTimestamp(array);
    console.log(timestamp);