How to get file creation date on browser using javascript or jquery

前端 未结 2 747
执笔经年
执笔经年 2021-01-23 00:49

I need to find out the file creation date and file last modified date while uploading the xls file, I have to do some calculation on this 2 dates.

By using below code I

相关标签:
2条回答
  • 2021-01-23 01:39

    You can not get the creation date. Only the last modified date is available in file properties.

    source: http://forum.jquery.com/topic/jquery-file-creation-date-before-upload

    For PHP there is a thread here that provides answer: PHP: how can I get file creation date?

    0 讨论(0)
  • 2021-01-23 01:41

    It seems unlike the lastModified property, there is no HTML DOM dateCreated property. So if JS needs to access the creation date of a document, it has to access it via the metadata of the file for which it should have access to the file system.

    JS not having access to the file system is a security feature in the browsers. But, in-case if someone is wanting to know how to get the creation date for the document for JS as in NodeJS (which of-course has the access to the file-system), then they can use the file system module to get the birthtime property as follows:

    const fs = require('fs');
    
    var file = "location-of-my-file";
    var dateCreated = fs.statSync(file).birthtime;
    
    console.log("This File was born on:" + dateCreated);
    

    NOTE : The above is only if you are programming a NodeJS app. This will not run on a normal web-browser, and will instead give the following console error : Uncaught ReferenceError: require is not defined.

    0 讨论(0)
提交回复
热议问题