其他分享
首页 > 其他分享> > 根据时间戳获取uuid

根据时间戳获取uuid

作者:互联网

  public getUuid(): string {
    let d = new Date().getTime();
    if (window.performance && typeof window.performance.now === 'function') {
        d += performance.now();
    }
    // tslint:disable-next-line
    const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        const r = (d + Math.random() * 16) % 16 | 0;
        d = Math.floor(d / 16);
        return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
    });
    return uuid;
  }

标签:const,uuid,16,根据,获取,window,performance,Math
来源: https://blog.csdn.net/weixin_42910115/article/details/122308475