How do I subtract minutes from a date in javascript?

后端 未结 9 2173
囚心锁ツ
囚心锁ツ 2020-11-29 03:25

How can I translate this pseudo code into working js [don\'t worry about where the end date comes from except that it\'s a valid javascript date].

var myEndD         


        
9条回答
  •  半阙折子戏
    2020-11-29 03:53

    var date=new Date();
    
    //here I am using "-30" to subtract 30 minutes from the current time.
    var minute=date.setMinutes(date.getMinutes()-30); 
    
    console.log(minute) //it will print the time and date according to the above condition in Unix-timestamp format.
    

    you can convert Unix timestamp into conventional time by using new Date().for example

    var extract=new Date(minute)
    console.log(minute)//this will print the time in the readable format.
    

提交回复
热议问题