diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/file/lastmodified/index.html | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/file/lastmodified/index.html')
-rw-r--r-- | files/zh-cn/web/api/file/lastmodified/index.html | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/file/lastmodified/index.html b/files/zh-cn/web/api/file/lastmodified/index.html new file mode 100644 index 0000000000..3f0a31de7c --- /dev/null +++ b/files/zh-cn/web/api/file/lastmodified/index.html @@ -0,0 +1,134 @@ +--- +title: File.lastModified +slug: Web/API/File/lastModified +tags: + - API + - File API + - Files +translation_of: Web/API/File/lastModified +--- +<p>{{APIRef("File API")}}</p> + +<p>只读属性 <code><strong>File.lastModified</strong></code> 返回所引用文件最后修改日期, 为自 1970年1月1日0:00 以来的毫秒数。没有已知的最后修改时间则会返回当前时间。</p> + +<h2 id="语法">语法</h2> + +<pre class="brush:js">var time = <em>instanceOfFile</em>.lastModified; +</pre> + +<h2 id="值">值</h2> + +<p>自 1970年1月1日0:00 以来的毫秒数。</p> + +<h2 id="实例">实例</h2> + +<h3 id="从INPUT标签读取文件">从INPUT标签读取文件</h3> + +<pre class="brush: html"><input type="file" multiple id="fileInput"> +</pre> + +<pre class="brush:js">const fileInput = document.getElementById('fileInput'); +fileInput.addEventListener('change', function(event) { + // files is a FileList object (simliar to NodeList) + const files = event.target.files; + + for (let i = 0; i < files.length; i++) { + const date = new Date(files[i].lastModified); + alert(files[i].name + ' has a last modified date of ' + date); + } +}); +</pre> + +<p>结果:</p> + +<p>{{ EmbedLiveSample('Reading_from_file_input', 300, 50) }}</p> + +<h3 id="动态创建文件">动态创建文件</h3> + +<p>如果文件是动态创建的,可以在构造函数{{domxref("File.File()", "new File()")}} 中提供最后修改时间。如果未提供则会继承文件对象被创建时的{{jsxref("Date.now()")}} 。</p> + +<pre class="brush:js">var fileWithDate = new File([], 'file.bin', { + lastModified: new Date(2017, 1, 1), +}); +console.log(fileWithDate.lastModified); //returns 1485903600000 + +var fileWithoutDate = new File([], 'file.bin'); +console.log(fileWithoutDate.lastModified); //returns current time +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('File API', '#file-attrs', 'lastModified')}}</td> + <td>{{Spec2('File API')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<p>{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>File.lastModified</td> + <td>13.0</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoDesktop("15.0")}}</td> + <td>10.0</td> + <td>16.0</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Edge</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>File.lastModified</td> + <td>{{CompatNo}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="参见">参见</h2> + +<ul> + <li>{{domxref("File")}}</li> +</ul> |