{"id":1884,"date":"2012-06-20T08:54:00","date_gmt":"2012-06-20T12:54:00","guid":{"rendered":""},"modified":"2013-11-23T14:54:45","modified_gmt":"2013-11-23T06:54:45","slug":"%e5%9c%a8%e4%b8%8d%e5%90%8c%e8%af%ad%e8%a8%80%e4%b8%ad%e8%bd%ac%e6%8d%a2%e8%8e%b7%e5%8f%96%e6%97%b6%e9%97%b4%e6%88%b3timestamp","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/1884.html","title":{"rendered":"\u5728\u4e0d\u540c\u8bed\u8a00\u4e2d\u8f6c\u6362\u83b7\u53d6\u65f6\u95f4\u6233(timestamp)"},"content":{"rendered":"<p>\u5982\u4f55\u5728\u4e0d\u540c\u7f16\u7a0b\u8bed\u8a00\u4e2d\u83b7\u53d6\u73b0\u5728\u7684Unix\u65f6\u95f4\u6233(Unix timestamp)\uff1f<\/p>\n<table>\n<tbody>\n<tr>\n<td>Java<\/td>\n<td>time<\/td>\n<\/tr>\n<tr>\n<td>JavaScript<\/td>\n<td>Math.round(new Date().getTime()\/1000)<br \/>\ngetTime()\u8fd4\u56de\u6570\u503c\u7684\u5355\u4f4d\u662f\u6beb\u79d2<\/td>\n<\/tr>\n<tr>\n<td>Microsoft .NET \/ C#<\/td>\n<td>epoch = (DateTime.Now.ToUniversalTime().Ticks &#8211; 621355968000000000) \/ 10000000<\/td>\n<\/tr>\n<tr>\n<td>MySQL<\/td>\n<td>SELECT unix_timestamp(now())<\/td>\n<\/tr>\n<tr>\n<td>Perl<\/td>\n<td>time<\/td>\n<\/tr>\n<tr>\n<td>PHP<\/td>\n<td>time()<\/td>\n<\/tr>\n<tr>\n<td>PostgreSQL<\/td>\n<td>SELECT extract(epoch FROM now())<\/td>\n<\/tr>\n<tr>\n<td>Python<\/td>\n<td>\u5148\u00a0import time\u00a0\u7136\u540e\u00a0time.time()<\/td>\n<\/tr>\n<tr>\n<td>Ruby<\/td>\n<td>\u83b7\u53d6Unix\u65f6\u95f4\u6233\uff1aTime.now\u00a0\u6216\u00a0Time.new<br \/>\n\u663e\u793aUnix\u65f6\u95f4\u6233\uff1aTime.now.to_i<\/td>\n<\/tr>\n<tr>\n<td>SQL Server<\/td>\n<td>SELECT DATEDIFF(s, &#8216;1970-01-01 00:00:00&#8217;, GETUTCDATE())<\/td>\n<\/tr>\n<tr>\n<td>Unix \/ Linux<\/td>\n<td>date +%s<\/td>\n<\/tr>\n<tr>\n<td>VBScript \/ ASP<\/td>\n<td>DateDiff(&#8220;s&#8221;, &#8220;01\/01\/1970 00:00:00&#8221;, Now())<\/td>\n<\/tr>\n<tr>\n<td>\u5176\u4ed6\u64cd\u4f5c\u7cfb\u7edf<br \/>\n(\u5982\u679cPerl\u88ab\u5b89\u88c5\u5728\u7cfb\u7edf\u4e2d)<\/td>\n<td>\u547d\u4ee4\u884c\u72b6\u6001\uff1aperl -e &#8220;print time&#8221;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div>\u5982\u4f55\u5728\u4e0d\u540c\u7f16\u7a0b\u8bed\u8a00\u4e2d\u5b9e\u73b0Unix\u65f6\u95f4\u6233(Unix timestamp) \u2192 \u666e\u901a\u65f6\u95f4\uff1f<\/div>\n<table>\n<tbody>\n<tr>\n<td>Java<\/td>\n<td>String date = new java.text.SimpleDateFormat(&#8220;dd\/MM\/yyyy HH:mm:ss&#8221;).format(new java.util.Date(Unix timestamp\u00a0* 1000))<\/td>\n<\/tr>\n<tr>\n<td>JavaScript<\/td>\n<td>\u5148\u00a0var unixTimestamp = new Date(Unix timestamp\u00a0* 1000)\u00a0\u7136\u540e commonTime = unixTimestamp.toLocaleString()<\/td>\n<\/tr>\n<tr>\n<td>Linux<\/td>\n<td>date -d @Unix timestamp<\/td>\n<\/tr>\n<tr>\n<td>MySQL<\/td>\n<td>from_unixtime(Unix timestamp)<\/td>\n<\/tr>\n<tr>\n<td>Perl<\/td>\n<td>\u5148\u00a0my $time =\u00a0Unix timestamp\u00a0\u7136\u540e my ($sec, $min, $hour, $day, $month, $year) = (localtime($time))[0,1,2,3,4,5,6]<\/td>\n<\/tr>\n<tr>\n<td>PHP<\/td>\n<td>date(&#8216;r&#8217;,\u00a0Unix timestamp)<\/td>\n<\/tr>\n<tr>\n<td>PostgreSQL<\/td>\n<td>SELECT TIMESTAMP WITH TIME ZONE &#8216;epoch&#8217; +\u00a0Unix timestamp) * INTERVAL &#8216;1 second&#8217;;<\/td>\n<\/tr>\n<tr>\n<td>Python<\/td>\n<td>\u5148\u00a0import time\u00a0\u7136\u540e\u00a0time.gmtime(Unix timestamp)<\/td>\n<\/tr>\n<tr>\n<td>Ruby<\/td>\n<td>Time.at(Unix timestamp)<\/td>\n<\/tr>\n<tr>\n<td>SQL Server<\/td>\n<td>DATEADD(s,\u00a0Unix timestamp, &#8216;1970-01-01 00:00:00&#8217;)<\/td>\n<\/tr>\n<tr>\n<td>VBScript \/ ASP<\/td>\n<td>DateAdd(&#8220;s&#8221;,\u00a0Unix timestamp, &#8220;01\/01\/1970 00:00:00&#8221;)<\/td>\n<\/tr>\n<tr>\n<td>\u5176\u4ed6\u64cd\u4f5c\u7cfb\u7edf<br \/>\n(\u5982\u679cPerl\u88ab\u5b89\u88c5\u5728\u7cfb\u7edf\u4e2d)<\/td>\n<td>\u547d\u4ee4\u884c\u72b6\u6001\uff1aperl -e &#8220;print scalar(localtime(Unix timestamp))&#8221;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div>\u5982\u4f55\u5728\u4e0d\u540c\u7f16\u7a0b\u8bed\u8a00\u4e2d\u5b9e\u73b0\u666e\u901a\u65f6\u95f4 \u2192 Unix\u65f6\u95f4\u6233(Unix timestamp)\uff1f<\/div>\n<table>\n<tbody>\n<tr>\n<td>Java<\/td>\n<td>long epoch = new java.text.SimpleDateFormat(&#8220;dd\/MM\/yyyy HH:mm:ss&#8221;).parse(&#8220;01\/01\/1970 01:00:00&#8221;);<\/td>\n<\/tr>\n<tr>\n<td>JavaScript<\/td>\n<td>var commonTime = new Date(Date.UTC(year,\u00a0month\u00a0&#8211; 1,\u00a0day,\u00a0hour,\u00a0minute,\u00a0second))<\/td>\n<\/tr>\n<tr>\n<td>MySQL<\/td>\n<td>SELECT unix_timestamp(time)<br \/>\n\u65f6\u95f4\u683c\u5f0f: YYYY-MM-DD HH:MM:SS \u6216 YYMMDD \u6216 YYYYMMDD<\/td>\n<\/tr>\n<tr>\n<td>Perl<\/td>\n<td>\u5148\u00a0use Time::Local\u00a0\u7136\u540e my $time = timelocal($sec, $min, $hour, $day, $month, $year);<\/td>\n<\/tr>\n<tr>\n<td>PHP<\/td>\n<td>mktime(hour,\u00a0minute,\u00a0second,\u00a0day,\u00a0month,\u00a0year)<\/td>\n<\/tr>\n<tr>\n<td>PostgreSQL<\/td>\n<td>SELECT extract(epoch FROM date(&#8216;YYYY-MM-DD HH:MM:SS&#8217;));<\/td>\n<\/tr>\n<tr>\n<td>Python<\/td>\n<td>\u5148\u00a0import time\u00a0\u7136\u540e\u00a0int(time.mktime(time.strptime(&#8216;YYYY-MM-DD HH:MM:SS&#8217;, &#8216;%Y-%m-%d %H:%M:%S&#8217;)))<\/td>\n<\/tr>\n<tr>\n<td>Ruby<\/td>\n<td>Time.local(year,\u00a0month,\u00a0day,\u00a0hour,\u00a0minute,\u00a0second)<\/td>\n<\/tr>\n<tr>\n<td>SQL Server<\/td>\n<td>SELECT DATEDIFF(s, &#8216;1970-01-01 00:00:00&#8217;,\u00a0time)<\/td>\n<\/tr>\n<tr>\n<td>Unix \/ Linux<\/td>\n<td>date +%s -d&#8221;Jan 1, 1970 00:00:01&#8243;<\/td>\n<\/tr>\n<tr>\n<td>VBScript \/ ASP<\/td>\n<td>DateDiff(&#8220;s&#8221;, &#8220;01\/01\/1970 00:00:00&#8221;,\u00a0time)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728\u4e0d\u540c\u7f16\u7a0b\u8bed\u8a00\u4e2d\u83b7\u53d6\u73b0\u5728\u7684Unix\u65f6\u95f4\u6233(Unix timestamp)\uff1f Java time JavaS [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-1884","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1884","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=1884"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1884\/revisions"}],"predecessor-version":[{"id":5147,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1884\/revisions\/5147"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=1884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=1884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=1884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}