<script type="application/ld+json">{"@context":"http://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://www.simcentric.com/tc/"},{"@type":"ListItem","position":2,"name":"獲取JavaScript時間戳有哪5種方法？","item":"https://www.simcentric.com/hong-kong-dedicated-server/what-are-the-5-methods-to-obtain-a-javascript-timestamp/"}]}</script> {"id":10851,"date":"2024-02-10T08:45:24","date_gmt":"2024-02-10T00:45:24","guid":{"rendered":"https:\/\/www.simcentric.com\/?p=10851"},"modified":"2024-02-02T10:32:16","modified_gmt":"2024-02-02T02:32:16","slug":"what-are-the-5-methods-to-obtain-a-javascript-timestamp","status":"publish","type":"post","link":"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/what-are-the-5-methods-to-obtain-a-javascript-timestamp\/","title":{"rendered":"\u7372\u53d6JavaScript\u6642\u9593\u6233\u6709\u54ea5\u7a2e\u65b9\u6cd5\uff1f"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><p>[vc_row el_class=&#8221;blog-detail-section&#8221;][vc_column][vc_column_text]<\/p>\n<p>\u5728\u65e5\u5e38\u7684Web\u958b\u767c\u4e2d\uff0c\u8655\u7406\u65e5\u671f\u548c\u6642\u9593\u662f\u4e0d\u53ef\u907f\u514d\u7684\u4efb\u52d9\u3002JavaScript\u4f5c\u70baWeb\u958b\u767c\u7684\u6838\u5fc3\u8a9e\u8a00\u4e4b\u4e00\uff0c\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u7684\u65b9\u6cd5\u4f86\u8655\u7406\u6642\u9593\uff0c\u5c24\u5176\u662f\u6642\u9593\u6233\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u7372\u53d6\u6642\u9593\u6233\u65b9\u6cd5\u548c\u8f49\u63dbJavaScript\u6642\u9593\u6233\u7684\u591a\u7a2e\u65b9\u6cd5\uff0c\u4e26\u5206\u4eab\u4e00\u4e9b\u5be6\u7528\u6280\u5de7\u3002<\/p>\n<p>[\/vc_column_text][\/vc_column][\/vc_row][vc_row el_class=&#8221;blog-detail-section&#8221;][vc_column][vc_column_text]<\/p>\n<h2><strong>\u7372\u53d6\u6642\u9593\u6233\u65b9\u6cd5<\/strong><\/h2>\n<p>\u4ee5\u4e0b\u662fJavaScript\u4e2d\u7372\u53d6\u7576\u524d\u6642\u9593\u6233\u7684\u4e94\u7a2e\u65b9\u6cd5\uff1a<\/p>\n<h3><strong>\u4f7f\u7528Date.now()\u65b9\u6cd5<\/strong><\/h3>\n<p>\u9019\u662f\u7372\u53d6\u7576\u524d\u6642\u9593\u6233\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u3002\u5b83\u8fd4\u56de\u8abf\u7528\u6642\u7684\u6beb\u79d2\u8868\u793a\u3002<\/p>\n<pre><code>console.log(Date.now()); \/\/ \u8f38\u51fa\u4f8b: 1642471441587<\/code><\/pre>\n<h3><strong>\u901a\u904eDate.parse()\u8f49\u63db\u6642\u9593\u5b57\u7b26\u4e32<\/strong><\/h3>\n<p>\u8a72\u65b9\u6cd5\u89e3\u6790\u4e00\u500b\u8868\u793a\u65e5\u671f\u7684\u5b57\u7b26\u4e32\uff0c\u4e26\u8fd4\u56de\u90a3\u500b\u65e5\u671f\u7684\u6642\u9593\u6233\u3002\u4f46\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5b83\u6703\u5c07\u6beb\u79d2\u503c\u8f49\u63db\u70ba000\u3002<\/p>\n<pre><code>console.log(Date.parse(new Date())); \/\/ \u8f38\u51fa\u4f8b: 1642471535000\r\nconsole.log(Date.parse(\"2022\/1\/18 10:05\")); \/\/ \u8f38\u51fa\u4f8b: 1642471500000<\/code><\/pre>\n<h3><strong>valueOf()\u65b9\u6cd5<\/strong><\/h3>\n<p>\u6b64\u65b9\u6cd5\u8fd4\u56deDate\u5c0d\u8c61\u7684\u539f\u59cb\u503c\uff0c\u5373\u6642\u9593\u6233\u3002<\/p>\n<pre><code>console.log((new Date()).valueOf()); \/\/ \u8f38\u51fa\u4f8b: 1642471624512<\/code><\/pre>\n<h3><strong>getTime()\u65b9\u6cd5<\/strong><\/h3>\n<p>\u9019\u500b\u65b9\u6cd5\u8fd4\u56de\u65e5\u671f\u5c0d\u8c61\u81ea1970\u5e741\u67081\u65e5 00:00:00 UTC\u4ee5\u4f86\u7d93\u904e\u7684\u6beb\u79d2\u6578\u3002<\/p>\n<pre><code>console.log(new Date().getTime()); \/\/ \u8f38\u51fa\u4f8b: 1642471711588<\/code><\/pre>\n<h3><strong>\u8f49\u63db\u70baNumber\u985e\u578b<\/strong><\/h3>\n<p>\u901a\u904e\u5c0dDate\u5c0d\u8c61\u4f7f\u7528Number\u69cb\u9020\u51fd\u6578\uff0c\u53ef\u4ee5\u5f97\u5230\u6642\u9593\u6233\u3002<\/p>\n<pre><code>console.log(Number(new Date())); \/\/ \u8f38\u51fa\u4f8b: 1642471746435<\/code><\/pre>\n<p>[\/vc_column_text][\/vc_column][\/vc_row][vc_row el_class=&#8221;blog-detail-section&#8221;][vc_column][vc_column_text]<\/p>\n<h2><strong>\u6642\u9593\u6233\u8f49\u63db\u70ba\u65e5\u671f<\/strong><\/h2>\n<p>\u7372\u53d6\u4e86\u6642\u9593\u6233\u4e4b\u5f8c\uff0c\u6211\u5011\u7d93\u5e38\u9700\u8981\u5c07\u5176\u8f49\u63db\u6210\u53ef\u8b80\u7684\u65e5\u671f\u683c\u5f0f\u3002\u4e0b\u9762\u662f\u5169\u7a2e\u5e38\u898b\u7684\u8f49\u63db\u65b9\u6cd5\uff1a<\/p>\n<h3><strong>\u8f49\u63db\u70ba\u672c\u5730\u6642\u9593\u5b57\u7b26\u4e32<\/strong><\/h3>\n<p>\u5229\u7528toLocaleString()\u65b9\u6cd5\u53ef\u4ee5\u7372\u5f97\u672c\u5730\u6642\u9593\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<pre><code>function getLocalTime(n) {\r\n    return new Date(parseInt(n)).toLocaleString().replace(\/:\\d{1,2}$\/, ' ');\r\n}\r\nconsole.log(getLocalTime(1642471746435)); \/\/ \u8f38\u51fa\u4f8b: '2022\/1\/18 \u4e0a\u534810:09'<\/code><\/pre>\n<h3><strong>\u683c\u5f0f\u5316\u70ba\u81ea\u5b9a\u7fa9\u683c\u5f0f<\/strong><\/h3>\n<p>\u53ef\u4ee5\u901a\u904e\u62fc\u63a5\u65e5\u671f\u7d44\u4ef6\u4f86\u5275\u5efa\u81ea\u5b9a\u7fa9\u683c\u5f0f\u7684\u65e5\u671f\u5b57\u7b26\u4e32\u3002<\/p>\n<pre><code>function customFormatDate(timestamp) {\r\n    let date = new Date(timestamp),\r\n        year = date.getFullYear(),\r\n        month = date.getMonth() + 1,\r\n        day = date.getDate(),\r\n        hour = date.getHours(),\r\n        minute = date.getMinutes(),\r\n        second = date.getSeconds();\r\n    return `${year}-${month}-${day} ${hour}:${minute}:${second}`;\r\n}\r\nconsole.log(customFormatDate(1642471746435)); \/\/ \u8f38\u51fa\u4f8b: '2022-1-18 10:09:06'<\/code><\/pre>\n<p>[\/vc_column_text][\/vc_column][\/vc_row]<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>[vc_row el_class=&#8221;blog-detail-section&#8221;][vc_ [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"https:\/\/www.simcentric.com\/tc\/hong-kong-dedicated-server-tc\/what-are-the-5-methods-to-obtain-a-javascript-timestamp\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":10848,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[61],"tags":[1512,1513],"class_list":["post-10851","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hong-kong-dedicated-server-tc","tag-javascript-timestamp-tc","tag-methods-to-obtain-timestamps-tc"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>\u7372\u53d6JavaScript\u6642\u9593\u6233\u6709\u54ea5\u7a2e\u65b9\u6cd5\uff1f | Simcentric Solutions<\/title>\n<meta name=\"description\" content=\"\u5728\u65e5\u5e38\u7684Web\u958b\u767c\u4e2d\uff0c\u8655\u7406\u65e5\u671f\u548c\u6642\u9593\u662f\u4e0d\u53ef\u907f\u514d\u7684\u4efb\u52d9\u3002JavaScript\u4f5c\u70baWeb\u958b\u767c\u7684\u6838\u5fc3\u8a9e\u8a00\u4e4b\u4e00\uff0c\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u7684\u65b9\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/10851\" \/>\n<meta property=\"og:locale\" content=\"zh_TW\" \/>\n<meta property=\"og:type\" content=\"company\" \/>\n<meta property=\"og:title\" content=\"\u7372\u53d6JavaScript\u6642\u9593\u6233\u6709\u54ea5\u7a2e\u65b9\u6cd5\uff1f | Simcentric Solutions\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/10851\" \/>\n<meta property=\"og:site_name\" content=\"\u65b0\u5929\u57df\u4e92\u806f\" \/>\n<meta property=\"article:published_time\" content=\"2024-02-10T00:45:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.simcentric.com\/wp-content\/uploads\/2024\/02\/sim-blog-2024-02-10C.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"602\" \/>\n\t<meta property=\"og:image:height\" content=\"596\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u7372\u53d6JavaScript\u6642\u9593\u6233\u6709\u54ea5\u7a2e\u65b9\u6cd5\uff1f | Simcentric Solutions","description":"\u5728\u65e5\u5e38\u7684Web\u958b\u767c\u4e2d\uff0c\u8655\u7406\u65e5\u671f\u548c\u6642\u9593\u662f\u4e0d\u53ef\u907f\u514d\u7684\u4efb\u52d9\u3002JavaScript\u4f5c\u70baWeb\u958b\u767c\u7684\u6838\u5fc3\u8a9e\u8a00\u4e4b\u4e00\uff0c\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u7684\u65b9","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/10851","og_locale":"zh_TW","og_type":"company","og_title":"\u7372\u53d6JavaScript\u6642\u9593\u6233\u6709\u54ea5\u7a2e\u65b9\u6cd5\uff1f | Simcentric Solutions","og_url":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/10851","og_site_name":"\u65b0\u5929\u57df\u4e92\u806f","article_published_time":"2024-02-10T00:45:24+00:00","og_image":[{"width":602,"height":596,"url":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2024\/02\/sim-blog-2024-02-10C.jpg","type":"image\/jpeg"}],"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/what-are-the-5-methods-to-obtain-a-javascript-timestamp\/#article","isPartOf":{"@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/what-are-the-5-methods-to-obtain-a-javascript-timestamp\/"},"author":{"name":"Tommy Cheung","@id":"https:\/\/simcentric.com\/tc\/#\/schema\/person\/631e153fdae3d1c71e500611868451e8"},"headline":"\u7372\u53d6JavaScript\u6642\u9593\u6233\u6709\u54ea5\u7a2e\u65b9\u6cd5\uff1f","datePublished":"2024-02-10T00:45:24+00:00","mainEntityOfPage":{"@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/what-are-the-5-methods-to-obtain-a-javascript-timestamp\/"},"wordCount":69,"publisher":{"@id":"https:\/\/simcentric.com\/tc\/#organization"},"image":{"@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/what-are-the-5-methods-to-obtain-a-javascript-timestamp\/#primaryimage"},"thumbnailUrl":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2024\/02\/sim-blog-2024-02-10C.jpg","keywords":["JavaScript\u6642\u9593\u6233","\u7372\u53d6\u6642\u9593\u6233\u65b9\u6cd5"],"articleSection":["\u9999\u6e2f\u4f3a\u670d\u5668"],"inLanguage":"zh-HK"},{"@type":"WebPage","@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/what-are-the-5-methods-to-obtain-a-javascript-timestamp\/","url":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/what-are-the-5-methods-to-obtain-a-javascript-timestamp\/","name":"\u7372\u53d6JavaScript\u6642\u9593\u6233\u6709\u54ea5\u7a2e\u65b9\u6cd5\uff1f | Simcentric Solutions","isPartOf":{"@id":"https:\/\/simcentric.com\/tc\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/what-are-the-5-methods-to-obtain-a-javascript-timestamp\/#primaryimage"},"image":{"@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/what-are-the-5-methods-to-obtain-a-javascript-timestamp\/#primaryimage"},"thumbnailUrl":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2024\/02\/sim-blog-2024-02-10C.jpg","datePublished":"2024-02-10T00:45:24+00:00","breadcrumb":{"@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/what-are-the-5-methods-to-obtain-a-javascript-timestamp\/#breadcrumb"},"inLanguage":"zh-HK","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/what-are-the-5-methods-to-obtain-a-javascript-timestamp\/"]}]},{"@type":"ImageObject","inLanguage":"zh-HK","@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/what-are-the-5-methods-to-obtain-a-javascript-timestamp\/#primaryimage","url":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2024\/02\/sim-blog-2024-02-10C.jpg","contentUrl":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2024\/02\/sim-blog-2024-02-10C.jpg","width":602,"height":596,"caption":"JavaScript\u6642\u9593\u6233"},{"@type":"BreadcrumbList","@id":"https:\/\/www.simcentric.com\/hong-kong-dedicated-server\/what-are-the-5-methods-to-obtain-a-javascript-timestamp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.simcentric.com\/tc\/"},{"@type":"ListItem","position":2,"name":"\u7372\u53d6JavaScript\u6642\u9593\u6233\u6709\u54ea5\u7a2e\u65b9\u6cd5\uff1f"}]},{"@type":"WebSite","@id":"https:\/\/simcentric.com\/tc\/#website","url":"https:\/\/simcentric.com\/tc\/","name":"Simcentric Solutions","description":"","publisher":{"@id":"https:\/\/simcentric.com\/tc\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/simcentric.com\/tc\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-HK"},{"@type":"Organization","@id":"https:\/\/simcentric.com\/tc\/#organization","name":"Simcentric Solutions","url":"https:\/\/simcentric.com\/tc\/","logo":{"@type":"ImageObject","inLanguage":"zh-HK","@id":"https:\/\/simcentric.com\/tc\/#\/schema\/logo\/image\/","url":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2023\/06\/sim-logo-2023.png","contentUrl":"https:\/\/www.simcentric.com\/wp-content\/uploads\/2023\/06\/sim-logo-2023.png","width":800,"height":222,"caption":"Simcentric Solutions"},"image":{"@id":"https:\/\/simcentric.com\/tc\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/simcentric.com\/tc\/#\/schema\/person\/631e153fdae3d1c71e500611868451e8","name":"Tommy Cheung","image":{"@type":"ImageObject","inLanguage":"zh-HK","@id":"https:\/\/secure.gravatar.com\/avatar\/a2e7d94371b76574e2ddc0f18834f815c0329507429c6613f6a7bc9435dc6fd2?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a2e7d94371b76574e2ddc0f18834f815c0329507429c6613f6a7bc9435dc6fd2?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a2e7d94371b76574e2ddc0f18834f815c0329507429c6613f6a7bc9435dc6fd2?s=96&d=mm&r=g","caption":"Tommy Cheung"},"sameAs":["https:\/\/simrevamp2023.sim-dp.com"]}]}},"_links":{"self":[{"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/10851","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/comments?post=10851"}],"version-history":[{"count":2,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/10851\/revisions"}],"predecessor-version":[{"id":10854,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/posts\/10851\/revisions\/10854"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/media\/10848"}],"wp:attachment":[{"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/media?parent=10851"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/categories?post=10851"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.simcentric.com\/tc\/wp-json\/wp\/v2\/tags?post=10851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}