From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- files/pt-pt/web/api/file/lastmodified/index.html | 113 +++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 files/pt-pt/web/api/file/lastmodified/index.html (limited to 'files/pt-pt/web/api/file/lastmodified') diff --git a/files/pt-pt/web/api/file/lastmodified/index.html b/files/pt-pt/web/api/file/lastmodified/index.html new file mode 100644 index 0000000000..9b05f6f3cf --- /dev/null +++ b/files/pt-pt/web/api/file/lastmodified/index.html @@ -0,0 +1,113 @@ +--- +title: File.lastModified +slug: Web/API/File/lastModified +tags: + - API + - Ficheiros + - File API + - Propriedade + - Referencia +translation_of: Web/API/File/lastModified +--- +
{{APIRef("File")}}
+ +

A propriedade read-only File.lastModified indica a ultima data em que o ficheiro foi modificado, na forma do numero de milissegundos desde o início da era Unix (1 de janeiro de 1970 às 00:00:00). Os ficheiros cuja a data da última modificação não é conhecida devolvem a data actual.

+ +

Sintaxe

+ +
const tempo = instanciaDeFicheiro.lastModified;
+
+ +

Valor

+ +

Um número que representa o número de milissegundos desde o início da época do Unix.

+ +

Exemplo

+ +

Leitura a partir da entrada do ficheiro

+ +
<input type="file" multiple id="entradaDeFicheiro">
+
+ +
const entradaDeFicheiro = document.querySelector('#entradaDeFicheiro');
+entradaDeFicheiro.addEventListener('change', (event) => {
+  // ficheiros é um objeto de FileList (semelhante a NodeList)
+  const ficheiros = event.target.files;
+
+  for (let ficheiro of ficheiros) {
+    const data = new Date(ficheiro.lastModified);
+    console.log(`${ficheiro.name} tem uma última data modificada de ${data}`);
+  }
+});
+
+ +

Veja os resultados abaixo:

+ +

{{ EmbedLiveSample('Leitura_a_partir_da_entrada_do_ficheiro', 300, 50) }}

+ +

Ficheiros criados dinamicamente

+ +

Se um objeto File for criado dinamicamente, a última data modificada pode ser fornecida na função construtor {{domxref("File.File()", "new File()")}}. Se estiver em falta, lastModified herda a hora actual de {{jsxref("Date.now()")}} no momento em que o objeto File é criado.

+ +
const ficheiroComData = new File([], 'file.bin', {
+  lastModified: new Date(2017, 1, 1),
+});
+console.log(ficheiroComData.lastModified); //devolve 1485903600000
+
+const ficheiroSemData = new File([], 'file.bin');
+console.log(ficheiroSemData.lastModified); //devolve data atual em milissegundos
+
+ +

Reduced time precision

+ +

To offer protection against timing attacks and fingerprinting, the precision of someFile.lastModified might get rounded depending on browser settings.
+ In Firefox, the privacy.reduceTimerPrecision  preference is enabled by default and defaults to 20us in Firefox 59; in 60 it will be 2ms.

+ +
// reduced time precision (2ms) in Firefox 60
+someFile.lastModified;
+// 1519211809934
+// 1519211810362
+// 1519211811670
+// ...
+
+
+// reduced time precision with `privacy.resistFingerprinting` enabled
+someFile.lastModified;
+// 1519129853500
+// 1519129858900
+// 1519129864400
+// ...
+
+ +

In Firefox, you can also enabled privacy.resistFingerprinting, the precision will be 100ms or the value of privacy.resistFingerprinting.reduceTimerPrecision.microseconds, whichever is larger.

+ +

Especificações

+ + + + + + + + + + + + + + + + +
EspecificaçãoEstadoComentários
{{SpecName('File API', '#file-attrs', 'lastModified')}}{{Spec2('File API')}}Definição inicial.
+ +

Compatibilidade

+ + + +

{{Compat("api.File.lastModified")}}

+ +

Ver também

+ + -- cgit v1.2.3-54-g00ecf