Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
Replace a substring by a rxjs countdowntimer

I am trying to implement a countdowntimer using rxjs in my angular 12 application. In my ts I have :

let timeLeft$ = interval(1000).pipe(
  map(x => this.calcTimeDiff(orderCutOffTime)),
  shareReplay(1)
);

calcTimeDiff() will return seconds, minutes and hours;

I have to create a string out of this and display that in the HTML. Basically replace an existing word in the string with timeLeft$ which will be a countdowntimer to be shown in the HTML.

Something like : this.orderCutOffMessage = someString.replace('Down', timeLeft$)

https://henrikmassow.medium.com/implement-a-countdown-timer-with-rxjs-in-angular-61600d1af00c

orderCutOffTime = "1645567200000" // Unix timestamp in milliseconds

private calcTimeDiff(cutOffTime: any): timeComponents {
const finalCutOffTime = (cutOffTime).valueOf();
const milliSecondsInASecond = 1000;
const hoursInADay = 24;
const minutesInAnHour = 60;
const secondsInAMinute = 60;
const timeDifference = finalCutOffTime - Date.now();

const hoursToFinalCutOffTime = Math.floor(
  (timeDifference /
    (milliSecondsInASecond * minutesInAnHour * secondsInAMinute)) %
  hoursInADay
);

const minutesToFinalCutOffTime = Math.floor(
  (timeDifference / (milliSecondsInASecond * minutesInAnHour)) %
  secondsInAMinute
);

const secondsToFinalCutOffTime =
  Math.floor(timeDifference / milliSecondsInASecond) % secondsInAMinute;


return { secondsToFinalCutOffTime, minutesToFinalCutOffTime, hoursToFinalCutOffTime };

}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here's a working example of your code https://stackblitz.com/edit/angular-material-table-data-source-znbvdb. It's basicly almost like the one in the link you shared, except that the names of the vars have been changed, one var discarded (days) and everything put in one .ts file. Please let me know if that's what you are looking for. Your orderCutOffTime has been hard-coded, but you are probably getting it in some subscription so you can tweak it. Also, timeString propably comes from subscription too.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!