--- title: <time> slug: Web/CSS/time tags: - CSS - CSS数据类型 - Web translation_of: Web/CSS/time --- <div>{{CSSRef}}</div> <p><strong><code><time></code></strong> <a href="/zh-CN/docs/Web/CSS">CSS</a> <a href="/zh-CN/docs/Web/CSS/CSS_Types">数据类型</a> 表达了以秒(s)或毫秒(ms)为单位的时间的值。于{{cssxref("animation")}}、{{cssxref("transition")}}及相关属性中使用。</p> <h2 id="语法">语法</h2> <p><code><time></code> 数据类型由{{cssxref("<number>")}}后加下方列出的单位之一组成。前方也可选择添加一个<code>+</code> 或 <code>-</code>。单位与数字之间无空格。</p> <div class="note"> <p><strong>注意:</strong>尽管数字 <code>0</code> 不管在何种单位下均相等,但其单位不可去除。 换句话说, <code>0</code> 是无效的,并不代表 <code>0s</code> 或 <code>0ms。</code></p> </div> <h3 id="单位">单位</h3> <dl> <dt><strong><code id="s">s</code></strong></dt> <dd>以秒为单位的时间。 例: <code>0s</code>, <code>1.5s</code>, <code>-60s</code>。</dd> <dt><strong><code id="ms">ms</code></strong></dt> <dd>以毫秒为单位的时间。例: <code>0ms</code>, <code>150.25ms</code>, <code>-60000ms</code>。</dd> </dl> <div class="note"> <p><strong>注意:</strong>秒 <code>s</code> 与毫秒 <code>ms</code> 间的转换为: <code>1s</code> = <code>1000ms</code>。</p> </div> <h2 id="示例">示例</h2> <h3 id="有效时间">有效时间</h3> <pre>12s 正整数 -456ms 负整数 4.3ms 非整数 14mS 单位大小写不敏感,虽然不推荐大写 +0s 0以及前置 + 号和单位 -0ms 0以及前置 - 号和单位 </pre> <h3 id="无效时间">无效时间</h3> <pre class="example-bad">0 尽管<length>中允许0,其在<time>中无效。 12.0 此为<number>而非<time>。其缺乏单位。 7 ms 数字与单位间不允许有空格。 </pre> <h2 id="规范">规范</h2> <table class="standard-table"> <thead> <tr> <th scope="col">规范</th> <th scope="col">状态</th> <th scope="col">注释</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('CSS4 Values','#time','<time>')}}</td> <td>{{Spec2('CSS4 Values')}}</td> <td> </td> </tr> <tr> <td>{{SpecName('CSS3 Values','#time','<time>')}}</td> <td>{{Spec2('CSS3 Values')}}</td> <td>规范定义 <code>s</code> 与 <code>ms</code>。</td> </tr> <tr> <td>{{SpecName('CSS2.1','aural.html#times','<time>')}}</td> <td>{{Spec2('CSS2.1')}}</td> <td>非正式定义<code>s</code> 与 <code>ms</code>。</td> </tr> </tbody> </table> <h2 id="浏览器兼容性">浏览器兼容性</h2> <p>{{Compat("css.types.time")}}</p> <div id="compat-mobile"> </div>