{"id":591,"date":"2025-12-05T13:19:38","date_gmt":"2025-12-05T05:19:38","guid":{"rendered":"https:\/\/www.idcyz.com\/blog\/?p=591"},"modified":"2025-12-05T13:19:38","modified_gmt":"2025-12-05T05:19:38","slug":"%e8%8e%b7%e5%8f%96%e5%bd%93%e5%89%8d%e6%97%b6%e9%97%b4%e7%9a%84ticks%e8%bf%9b%e8%a1%8c%e9%ab%98%e7%b2%be%e5%ba%a6%e6%97%b6%e9%97%b4%e7%ae%a1%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.idcyz.com\/blog\/591.html","title":{"rendered":"\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u7684ticks\u8fdb\u884c\u9ad8\u7cbe\u5ea6\u65f6\u95f4\u7ba1\u7406"},"content":{"rendered":"<p><p>\u5728Python\u4e2d\uff0c\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u7684\u201cticks\u201d\u662f\u4e00\u79cd\u5229\u7528\u65e5\u671f\u548c\u65f6\u95f4\u5e93\u8fdb\u884c\u7cbe\u786e\u65f6\u95f4\u7ba1\u7406\u7684\u65b9\u6cd5\u3002\u8fd9\u4e2a\u64cd\u4f5c\u53ef\u4ee5\u7528\u4e8e\u9700\u8981\u9891\u7e41\u68c0\u67e5\u65f6\u95f4\u5dee\u7684\u7a0b\u5e8f\uff0c\u5c24\u5176\u5728\u8ba1\u65f6\u3001\u6027\u80fd\u5206\u6790\u7b49\u65b9\u9762\u6709\u7740\u5e7f\u6cdb\u5e94\u7528\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Python\u4e2d\u7684 <strong>datetime.now().ticks<\/strong> \u8fdb\u884c\u65f6\u95f4\u6233\u7684\u83b7\u53d6\u548c\u4f7f\u7528\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.idcyz.com\/blog\/wp-content\/uploads\/2025\/07\/ffBnBf.jpg\" alt=\"\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u7684ticks\u8fdb\u884c\u9ad8\u7cbe\u5ea6\u65f6\u95f4\u7ba1\u7406\" title=\"\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u7684ticks\u8fdb\u884c\u9ad8\u7cbe\u5ea6\u65f6\u95f4\u7ba1\u7406\"><\/p>\n<\/p>\n<p><h2>\u64cd\u4f5c\u524d\u7684\u51c6\u5907\u4e0e\u80cc\u666f\u4ecb\u7ecd<\/h2>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u786e\u4fdd\u60a8\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u53ca\u76f8\u5173\u7684\u4f9d\u8d56\u5e93\u3002\u901a\u5e38\uff0c\u6807\u51c6\u7684Python\u5b89\u88c5\u4e2d\u5df2\u7ecf\u5305\u542b\u4e86 <strong>datetime<\/strong> \u5e93\uff0c\u4f46\u5982\u679c\u5728\u7279\u5b9a\u73af\u5883\u4e2d\u7f3a\u5931\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5:<\/p>\n<\/p>\n<p><pre><code>pip install datetime<\/code><\/pre>\n<\/p>\n<p><p>\u4e86\u89e3\u65f6\u95f4\u7684\u201cticks\u201d\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u8fdb\u884c\u65f6\u95f4\u95f4\u9694\u7684\u8ba1\u7b97\u548c\u4e8b\u4ef6\u7684\u8c03\u5ea6\u3002\u901a\u8fc7\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u7684ticks\uff0c\u60a8\u53ef\u4ee5\u5b9e\u73b0\u9ad8\u7cbe\u5ea6\u7684\u65f6\u95f4\u8bb0\u5f55\u3002<\/p>\n<\/p>\n<p><h2>\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u7684ticks\u7684\u8be6\u7ec6\u64cd\u4f5c\u6307\u5357<\/h2>\n<\/p>\n<p><h3>\u6b65\u9aa41\uff1a\u5bfc\u5165\u76f8\u5173\u5e93<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u5bfc\u5165datetime\u5e93\u3002\u6253\u5f00Python\u89e3\u91ca\u5668\u6216\u60a8\u7684\u5f00\u53d1\u73af\u5883\uff0c\u5e76\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801:<\/p>\n<\/p>\n<p><pre><code>from datetime import datetime<\/code><\/pre>\n<\/p>\n<p><h3>\u6b65\u9aa42\uff1a\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u7684ticks<\/h3>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u60a8\u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u7684ticks\u3002\u4ee5\u4e0b\u662f\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u548cticks\u7684\u793a\u4f8b\u4ee3\u7801:<\/p>\n<\/p>\n<p><pre><code>current_time = datetime.now()<\/p>\r\n<p>ticks = int(current_time.timestamp() * 1e7)  # \u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u4e3aticks<\/p>\r\n<p>print(\"\u5f53\u524d\u65f6\u95f4:\", current_time)<\/p>\r\n<p>print(\"\u5f53\u524d\u65f6\u95f4\u7684ticks:\", ticks)<\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u91cc\uff0c<strong>timestamp()<\/strong> \u65b9\u6cd5\u8fd4\u56de\u81ea1970\u5e741\u67081\u65e5\u4ee5\u6765\u7684\u79d2\u6570\uff0c\u800c\u4e58\u4ee5 <strong>1e7<\/strong> \u5c31\u662f\u5c06\u79d2\u8f6c\u6362\u4e3aticks\u3002<\/p>\n<\/p>\n<p><h3>\u6b65\u9aa43\uff1a\u7406\u89e3\u548c\u4f7f\u7528ticks<\/h3>\n<\/p>\n<p><p>\u83b7\u53d6\u5230\u7684ticks\u503c\u53ef\u4ee5\u7528\u4e8e\u591a\u79cd\u7528\u9014\uff0c\u6bd4\u5982\u8bb0\u5f55\u4e8b\u4ef6\u65f6\u95f4\u3001\u8ba1\u7b97\u65f6\u95f4\u5dee\u7b49\u3002\u60a8\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528\u8fd9\u4e9bticks\u8fdb\u884c\u5404\u79cd\u8ba1\u7b97:<\/p>\n<\/p>\n<p><pre><code># \u8bb0\u5f55\u4e00\u4e2a\u4e8b\u4ef6\u7684\u65f6\u95f4<\/p>\r\n<p>start_ticks = ticks<\/p>\r\n\r\n<p># \u6a21\u62df\u4e00\u4e9b\u5904\u7406<\/p>\r\n<p>import time<\/p>\r\n<p>time.sleep(2)  # \u5047\u8bbe\u5904\u7406\u82b1\u8d39\u4e862\u79d2<\/p>\r\n\r\n<p>end_ticks = int(datetime.now().timestamp() * 1e7)<\/p>\r\n<p>elapsed_ticks = end_ticks - start_ticks<\/p>\r\n\r\n<p>print(\"\u64cd\u4f5c\u8017\u65f6\uff08ticks\uff09:\", elapsed_ticks)<\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u8ba1\u7b97\u51fa\u64cd\u4f5c\u7684\u8017\u65f6 ticks \u6570\u3002<\/p>\n<\/p>\n<p><h2>\u547d\u4ee4\u548c\u5173\u952e\u6982\u5ff5\u7684\u89e3\u91ca<\/h2>\n<\/p>\n<p><p><strong>datetime<\/strong>: \u8fd9\u662fPython\u7684\u4e00\u90e8\u5206\uff0c\u63d0\u4f9b\u65e5\u671f\u548c\u65f6\u95f4\u7684\u64cd\u4f5c\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><p><strong>timestamp()<\/strong>: \u8fd4\u56dedatetime\u5bf9\u8c61\u7684\u65f6\u95f4\u6233\uff0c\u5373\u81ea1970\u5e741\u67081\u65e5UTC\u4ee5\u6765\u7684\u79d2\u6570\u3002<\/p>\n<\/p>\n<p><p><strong>ticks<\/strong>: \u4e00\u822c\u6307\u7684\u662f\u5c0f\u4e8e\u4e00\u79d2\u7684\u8f83\u5c0f\u65f6\u95f4\u5355\u4f4d\uff0c\u5728\u6b64\u4e0a\u4e0b\u6587\u4e2d\uff0c\u6307\u7684\u662f\u5c06\u65f6\u95f4\u8f6c\u6362\u4e3a\u4ee5\u5341\u4ebf\u5206\u4e4b\u4e00\u79d2\u8ba1\u6570\u7684\u5355\u4f4d\u3002<\/p>\n<\/p>\n<p><h2>\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u7684\u95ee\u9898\u4e0e\u6ce8\u610f\u4e8b\u9879<\/h2>\n<\/p>\n<ul>\n<li><strong>\u7cfb\u7edf\u65f6\u95f4\u8bbe\u7f6e\u4e0d\u51c6\u786e<\/strong>: \u5982\u679c\u60a8\u83b7\u53d6\u7684\u65f6\u95f4\u4e0d\u6b63\u786e\uff0c\u8bf7\u68c0\u67e5\u60a8\u7684\u7cfb\u7edf\u65f6\u95f4\u8bbe\u7f6e\uff0c\u786e\u4fdd\u60a8\u7684\u670d\u52a1\u5668\u6216\u672c\u5730\u8ba1\u7b97\u673a\u7684\u65f6\u95f4\u662f\u51c6\u786e\u7684\u3002<\/li>\n<li><strong>ticks\u4e0d\u7b49\u4e8e\u6beb\u79d2<\/strong>: \u786e\u4fdd\u60a8\u7406\u89e3 ticks \u662f\u5982\u4f55\u8ba1\u7b97\u7684\uff1b\u5728\u6b64\u4f8b\u4e2d\uff0c\u4e3a\u4e86\u83b7\u53d6\u51c6\u786e\u7684ticks\uff0c\u987b\u5c06\u65f6\u95f4\u6233\u6309 <strong>1e7<\/strong> \u8fdb\u884c\u8c03\u6574\u3002<\/li>\n<li><strong>\u6027\u80fd\u95ee\u9898<\/strong>: \u5728\u9ad8\u9891\u7387\u7684\u5faa\u73af\u4e2d\u9891\u7e41\u8c03\u7528\u5f53\u524d\u65f6\u95f4\u53ef\u80fd\u4f1a\u5f71\u54cd\u6027\u80fd\uff0c\u5c3d\u91cf\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u65f6\u95f4\u68c0\u67e5\u3002<\/li>\n<\/ul>\n<p><h2>\u5b9e\u7528\u6280\u5de7<\/h2>\n<\/p>\n<ul>\n<li>\u5728\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u7a0b\u5e8f\u4e2d\uff0c\u53ef\u4ee5\u5148\u8bb0\u5f55\u4e0b\u65f6\u95f4\u7684ticks\uff0c\u7136\u540e\u5728\u67d0\u4e9b\u4e8b\u4ef6\u5b8c\u6210\u540e\uff0c\u518d\u8ba1\u7b97\u4e0e\u539f\u59cbticks\u7684\u5dee\u503c\uff0c\u4ee5\u4f18\u5316\u6027\u80fd\u3002<\/li>\n<li>\u5bf9\u4e8e\u9ad8\u5e76\u53d1\u7684\u670d\u52a1\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u65f6\u95f4\u6233\u7684\u5fae\u8c03\u7b56\u7565\u6765\u786e\u4fdd\u4e0d\u4f1a\u53d1\u751f\u4e8b\u4ef6\u7684\u91cd\u53e0\uff0c\u9020\u6210\u65f6\u95f4\u8bb0\u5f55\u7684\u9519\u8bef\u3002<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u672c\u6307\u5357\uff0c\u60a8\u5e94\u8be5\u80fd\u591f\u638c\u63e1\u5982\u4f55\u5728Python\u4e2d\u83b7\u53d6\u548c\u4f7f\u7528\u5f53\u524d\u65f6\u95f4\u7684ticks\uff0c\u4ece\u800c\u63d0\u5347\u60a8\u7684\u7f16\u7801\u6548\u7387\u53ca\u5904\u7406\u65f6\u95f4\u76f8\u5173\u9700\u6c42\u7684\u80fd\u529b\u3002<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Python\u4e2d\uff0c\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u7684\u201cticks\u201d\u662f\u4e00\u79cd\u5229\u7528\u65e5\u671f\u548c\u65f6\u95f4\u5e93\u8fdb\u884c\u7cbe\u786e\u65f6\u95f4\u7ba1\u7406\u7684\u65b9\u6cd5\u3002\u8fd9\u4e2a\u64cd\u4f5c\u53ef\u4ee5\u7528\u4e8e\u9700\u8981\u9891\u7e41\u68c0\u67e5\u65f6\u95f4\u5dee\u7684\u7a0b\u5e8f\uff0c\u5c24\u5176\u5728\u8ba1\u65f6\u3001\u6027\u80fd\u5206\u6790\u7b49\u65b9\u9762\u6709\u7740\u5e7f\u6cdb\u5e94\u7528\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Python\u4e2d\u7684 datetime.now()&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":592,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[12,309,310],"topic":[],"class_list":["post-591","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jiushu","tag-python","tag-ticks","tag-310"],"_links":{"self":[{"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/posts\/591","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/comments?post=591"}],"version-history":[{"count":1,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/posts\/591\/revisions"}],"predecessor-version":[{"id":594,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/posts\/591\/revisions\/594"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/media\/592"}],"wp:attachment":[{"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/media?parent=591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/categories?post=591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/tags?post=591"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.idcyz.com\/blog\/wp-json\/wp\/v2\/topic?post=591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}