当前位置:网站首页>JS synchronizes the local time with the server time
JS synchronizes the local time with the server time
2022-07-28 17:37:00 【yoki 】
Be careful , The code uses angular Format method of time in , If you don't use it angular, You can find a way to format the time instead !
1. First, get the time interval between local time and server time .( Here, assume that the time transmitted by the server is 2016-05-25 16:20:00)
var timeDiff=dateDiff($filter('date')(new Date(), 'yyyy-MM-dd HH:mm:ss'),'2016-05-25 16:20'); function dateDiff(date1,date2){ return (new Date(date2))-(new Date(date1)); }2. Each local time plus this time interval is the time of the server .
var ServerDate = +new Date()+timeDiff;
Of course, this is also flawed , That is the local time in the code 1 After the operation is artificially changed, the time is not the time of the server .
边栏推荐
- C # basic interview questions (with answers)
- Talk about what you know about publishing online (I)
- Create a custom paging control
- Verilog daily question (vl8 uses generate... For statement to simplify code)
- 漫谈测试平台—建设模式探讨
- Master the key points of JVM interview
- Encountered.Sqlite file processing during Android Development
- Verilog daily question (VL2 asynchronous reset Series T trigger - Niuke network)
- Deploy lamp platform -- compilation and installation of Linux, Apache, MySQL and PHP
- Visual Object Class介绍PASCAL VOC数据集
猜你喜欢
随机推荐
Basic principle of asynchronous FIFO (simple implementation based on Verilog)
JDWP未授权快速利用
C language to achieve minesweeping games
js将本地时间与服务器时间同步
高速电路设计实践——概述
Verilog daily question (simple implementation of VL30 RAM)
Vscode uses eslint prettier to format code automatically
【sqoop】sqoop1.4.7 安装集成CDH5.13
Flat data to tree
异步FIFO基本原理(基于Verilog的简单实现)
MySQL的触发器
Selection and application of inductors in high speed circuits
【impala】【报错解决】 Impala cannot read or execute the parent directory of dfs.domain.socket.path的解决方法
Blue Bridge Cup embedded competition resources and skills
Verilog daily question (vl5 signal generator)
部署LAMP平台---Linux,Apache,MySQL,PHP的编译安装
Verilog daily question (vl4 shift operation and multiplication)
阿里P8架构师谈:成为架构师必须学好的七大知识点(含面试题)
Encrypt the video and upload it to OSS to achieve high concurrent access
Zero foundation uses unity3d to develop AR applications and download 3D models remotely








