Guest User

Untitled

a guest
Dec 16th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. //get the server date
  2. this.service.getServerTime().subscribe(serverDate => {
  3. this.serverDate = serverDate;
  4. }, error => { });
  5.  
  6. //start the timer using observable
  7. let timer = Observable.timer(1000, 1000);
  8. this.timerSubscription = timer.subscribe((t: any) => {
  9. this.timerExecuted();
  10. });
  11.  
  12. private timerExecuted(): void {
  13. if (!this.serverDate) {
  14. return;
  15. }
  16. //add 1 second to the server date
  17. this.serverDate.setSeconds(this.serverDate.getSeconds() + 1);
  18.  
  19. //console log the server date after adding 1 second
  20. console.log(this.serverDate);
  21. }
Add Comment
Please, Sign In to add comment