【问题标题】:how to get time remains for cookie expiration in seconds?如何以秒为单位获取 cookie 过期的剩余时间?
【发布时间】:2018-02-12 09:57:07
【问题描述】:

我设置了 2 分钟过期时间的 cookie。 我想在 HTML 上显示倒计时,角度 2 中的特定 cookie 过期还剩多少秒。

【问题讨论】:

标签: javascript angularjs angular


【解决方案1】:

你可以使用

import { timer } from 'rxjs/observable/timer';
import { take, map } from 'rxjs/operators';

@Component({
   selector: 'my-app',
   template: `<h2>{{countDown | async}}</h2>`
})
export class App {
   countDown;
   count = 60;

   constructor() {

       this.countDown = timer(0,1000).pipe(
          take(this.count),
          map(()=> --this.count)
       );
   }
}

所以在设置 cookie 时间时,您也可以在计时器中设置相同的时间。确保您分配您的 cookie 时间和此计时器时间相同的确切工作。

工作示例是here

【讨论】:

  • 这个只显示倒计时,我想得到cookie过期的铰链时间,我怎么能得到它
  • 所以我给了你逻辑答案,你需要得到这个链接stackoverflow.com/questions/3274875/…中提到的时间并将时间传递给我的函数
猜你喜欢
  • 2012-03-31
  • 1970-01-01
  • 2011-04-19
  • 1970-01-01
  • 2010-12-02
  • 2021-05-31
  • 1970-01-01
  • 1970-01-01
  • 2017-01-10
相关资源
最近更新 更多