JavaScript/Date:修订间差异
来自康健生活
| 第21行: | 第21行: | ||
1639973532000 | 1639973532000 | ||
</pre>}}}} | </pre>}}}} | ||
==== data 转 iso ==== | |||
{{leftrightflex|<syntaxhighlight lang="javascript"> | |||
new Date().toISOString().replace(/\..+/,'') + 'Z'</syntaxhighlight>|{{consoleout|<pre>'2022-07-05T03:49:08Z' | |||
</pre>}}}} | |||
==== 13 转 10 ==== | |||
{{leftrightflex|<syntaxhighlight lang="javascript"> | |||
parseInt((new Date()).getTime() / 1000);</syntaxhighlight>|{{consoleout|<pre>1656993199 | |||
</pre>}}}} | |||
==== 转普通日期 ==== | |||
{{leftrightflex|<syntaxhighlight lang="javascript"> | |||
// 1656993199 毫秒时间戳 | |||
new Date(parseInt(1656993199) * 1000).toLocaleString().replace(/:\d{1,2}$/,'');</syntaxhighlight>|{{consoleout|<pre>'2022/7/5 11:53' | |||
</pre>}}}} | |||
=== 时间戳 === | |||
{{leftrightflex|<syntaxhighlight lang="javascript"> | |||
Date.parse(new Date()); | |||
(new Date()).valueOf(); | |||
new Date().getTime();</syntaxhighlight>|{{consoleout|<pre> | |||
</pre>}}}} | |||
== function == | == function == | ||
=== Date.parse === | === Date.parse === | ||