0

I'm trying to display the last updated time of a file (not my html file, another file).

HTML:

<p>Last updated: <span id="lastUpdate"></span></p>

JavaScript:

var file = 'data/myFile.csv';
var modifiedTime = new Date(file.lastModified);
document.getElementById('lastUpdate').innerHTML = modifiedTime;

When I run it, it just displays the following; (with no errors in the console)

Last updated: Invalid Date


I'm obviously missing something, probably something small.

Edit:

My files are setup like below:

site/index.html
site/data/myFile.csv
site/js/lastUpdate.js
Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345
Welz
  • 236
  • 2
  • 10
  • 21

1 Answers1

-1

Yes - when you declare variable

var file = 'data/myFile.csv'

in file variable you have only file path - not file content (to read it you can use fetch). The second thing- when you read file content - then you should parse it - to read proper csv column

Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345