When I output a date in php or javascript, how is it calculated? Is it affected by the time a user has set on his computer or is it taken from an external source? If the user can affect it, then how do I make sure my code gets the real date/time?
2条回答 默认 最新
- doujie4344 2017-06-02 11:24关注
There is a difference in technology and the context of these technologies. Meaning front-end (client side) or back-end (server side). The difference in
PHP
andJavaScript
are on the level of invokement.PHP
PHP
is run on a dedicated server, not a clients machine. When the time function is invoked from within thePHP
context, the time will be taken from the server side. Meaning the time of the hosting server.JavaScript
JavaScript
is running at client side level (browser). Time taken within theJavaScript
context will take the clients operating system time. Changing your operating system time settings will have effect on yourJavaScript
time fetching.In this case we are not taking into account any
JavaScript
back-end, likeNodeJS
. Since this behaves as the above mentionedPHP
context.Whenever I need to ensure correct Date/Time on a client side
JavaScript
application, I'll launch a REST request to retrieve the server time. Counting on the server time takes into account that only authenticated system admin's have control on the server Data/Time settings. And we can rely on this Date/Time truth.本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 牛顿斯科特系数表表示
- ¥15 arduino 步进电机
- ¥20 程序进入HardFault_Handler
- ¥15 oracle集群安装出bug
- ¥15 关于#python#的问题:自动化测试
- ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
- ¥15 教务系统账号被盗号如何追溯设备
- ¥20 delta降尺度方法,未来数据怎么降尺度
- ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
- ¥15 再不同版本的系统上,TCP传输速度不一致