{"id":1348,"date":"2024-11-10T15:55:57","date_gmt":"2024-11-10T07:55:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1348\/"},"modified":"2024-11-10T15:55:57","modified_gmt":"2024-11-10T07:55:57","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-javascript-%e5%ae%9a%e6%97%b6%e8%8e%b7%e5%8f%96%e6%95%b0%e6%8d%ae%e5%ba%93%e6%97%b6%e9%97%b4%e5%b9%b6%e6%af%94%e8%be%83%ef%bc%8c%e5%b9%b6%e5%9c%a8%e5%bd%93","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1348\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 JavaScript \u5b9a\u65f6\u83b7\u53d6\u6570\u636e\u5e93\u65f6\u95f4\u5e76\u6bd4\u8f83\uff0c\u5e76\u5728\u5f53\u524d\u65f6\u95f4\u8d85\u8fc7\u6570\u636e\u5e93\u65f6\u95f4\u65f6\u6267\u884c\u64cd\u4f5c\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173037496170310.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 JavaScript \u5b9a\u65f6\u83b7\u53d6\u6570\u636e\u5e93\u65f6\u95f4\u5e76\u6bd4\u8f83\uff0c\u5e76\u5728\u5f53\u524d\u65f6\u95f4\u8d85\u8fc7\u6570\u636e\u5e93\u65f6\u95f4\u65f6\u6267\u884c\u64cd\u4f5c\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 JavaScript \u5b9a\u65f6\u83b7\u53d6\u6570\u636e\u5e93\u65f6\u95f4\u5e76\u6bd4\u8f83\uff0c\u5e76\u5728\u5f53\u524d\u65f6\u95f4\u8d85\u8fc7\u6570\u636e\u5e93\u65f6\u95f4\u65f6\u6267\u884c\u64cd\u4f5c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>js\u5b9a\u65f6\u83b7\u53d6\u6570\u636e\u5e93\u65f6\u95f4\u5e76\u6bd4\u8f83<\/strong><\/p>\n<p>\u9700\u8981\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u4ece\u6570\u636e\u5e93\u83b7\u53d6\u65f6\u95f4\uff0c\u5e76\u5c06\u5b83\u4e0e\u5f53\u524d\u65f6\u95f4\u8fdb\u884c\u6bd4\u8f83\u3002\u5f53\u5f53\u524d\u65f6\u95f4\u5927\u4e8e\u6570\u636e\u5e93\u65f6\u95f4\u65f6\uff0c\u6267\u884c\u7279\u5b9a\u7684\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u65f6\u95f4\u6bd4\u8f83\u51fd\u6570\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>function comparetimestamps(dbtimestamp, currenttime) {\n  return dbtimestamp &lt; currenttime;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u5916\u90e8\u521b\u5efa\u4e00\u4e2a\u51fd\u6570\u6765\u8c03\u7528\u8be5\u65f6\u95f4\u6bd4\u8f83\u51fd\u6570\u3002<\/p>\n<pre>async function checktimestamp() {\n  \/\/ \u6bcf\u9694 1 \u79d2\u83b7\u53d6\u6570\u636e\u5e93\u65f6\u95f4\n  const dbtimestamp = await getdatabasetimestamp();\n\n  \/\/ \u83b7\u53d6\u5f53\u524d\u65f6\u95f4\n  const currenttime = new date();\n\n  \/\/ \u6bd4\u8f83\u65f6\u95f4\u6233\n  const iscurrenttimegreater = comparetimestamps(dbtimestamp, currenttime);\n\n  if (iscurrenttimegreater) {\n    \/\/ \u5f53\u5f53\u524d\u65f6\u95f4\u5927\u4e8e\u6570\u636e\u5e93\u65f6\u95f4\u65f6\uff0c\u6267\u884c\u64cd\u4f5c\n    executeoperation();\n  }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728 finally \u4e2d\u8bbe\u7f6e\u4e00\u4e2a\u8ba1\u65f6\u5668\uff0c\u8ba9\u51fd\u6570\u6bcf\u9694 1 \u79d2\u8c03\u7528\u4e00\u6b21\u3002<\/p>\n<pre>\/\/ \u8bbe\u7f6e\u6bcf 1 \u79d2\u8c03\u7528\u4e00\u6b21\nsetInterval(checkTimestamp, 1000);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6267\u884c\u64cd\u4f5c\uff1a<\/strong><\/p>\n<p>\u5728 executeoperation() \u51fd\u6570\u4e2d\u5b9a\u4e49\u9700\u8981\u5728\u5f53\u524d\u65f6\u95f4\u5927\u4e8e\u6307\u5b9a\u65f6\u95f4\u65f6\u6267\u884c\u7684\u64cd\u4f5c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 JavaScript \u5b9a\u65f6\u83b7\u53d6\u6570\u636e\u5e93\u65f6\u95f4\u5e76\u6bd4\u8f83\uff0c\u5e76\u5728\u5f53\u524d\u65f6\u95f4\u8d85\u8fc7\u6570\u636e\u5e93\u65f6\u95f4\u65f6\u6267\u884c\u64cd\u4f5c\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>js\u5b9a\u65f6\u83b7\u53d6\u6570\u636e\u5e93\u65f6\u95f4\u5e76\u6bd4\u8f83 \u9700\u8981\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u4ece\u6570\u636e\u5e93\u83b7\u53d6\u65f6\u95f4\uff0c\u5e76\u5c06\u5b83\u4e0e\u5f53\u524d\u65f6\u95f4\u8fdb\u884c\u6bd4\u8f83\u3002\u5f53\u5f53\u524d\u65f6\u95f4\u5927\u4e8e\u6570\u636e\u5e93\u65f6\u95f4\u65f6\uff0c\u6267\u884c\u7279\u5b9a\u7684\u64cd\u4f5c\u3002 \u89e3\u51b3\u65b9\u6848\uff1a \u521b\u5efa\u4e00\u4e2a\u65f6\u95f4\u6bd4\u8f83\u51fd\u6570\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b function comparetimestamps(dbtimestamp, currenttime) { return dbtimestamp &lt; currenttime; } \u767b\u5f55\u540e\u590d\u5236 \u5728\u5916\u90e8\u521b\u5efa\u4e00\u4e2a\u51fd\u6570\u6765\u8c03\u7528\u8be5\u65f6\u95f4\u6bd4\u8f83\u51fd\u6570\u3002 async function checktimestamp() { \/\/ \u6bcf\u9694 1 \u79d2\u83b7\u53d6\u6570\u636e\u5e93\u65f6\u95f4 const dbtimestamp = await getdatabasetimestamp(); \/\/ \u83b7\u53d6\u5f53\u524d\u65f6\u95f4 const currenttime = new date(); \/\/ \u6bd4\u8f83\u65f6\u95f4\u6233 const iscurrenttimegreater = comparetimestamps(dbtimestamp, currenttime); if (iscurrenttimegreater) { \/\/ \u5f53\u5f53\u524d\u65f6\u95f4\u5927\u4e8e\u6570\u636e\u5e93\u65f6\u95f4\u65f6\uff0c\u6267\u884c\u64cd\u4f5c executeoperation(); } } \u767b\u5f55\u540e\u590d\u5236 \u5728 finally \u4e2d\u8bbe\u7f6e\u4e00\u4e2a\u8ba1\u65f6\u5668\uff0c\u8ba9\u51fd\u6570\u6bcf\u9694 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1348","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1348","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=1348"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1348\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1348"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}