Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

calculate time in seconds javascript angular

// Calculate response time in seconds
let startFrom = new Date().getTime();
let seconds = Math.round(new Date().getTime() - startFrom) / 1000;
console.log(`Time: ${seconds}s`);

// Example: Calculating Angular service call's response time:
calculateTime(param: any) {
  let startFrom = new Date().getTime();
  
  this.myService.getData(param).subscribe(
    (res) => {
      let seconds = Math.round(new Date().getTime() - startFrom) / 1000;
      console.log(`Time: ${seconds}s`);
    },
    (error) => {
      // etc
    })
}
 
PREVIOUS NEXT
Tagged: #calculate #time #seconds #javascript #angular
ADD COMMENT
Topic
Name
3+9 =