Jump to content

JS: Kā nolasīt faila lastModified atribūtu?


Taksis
 Share

Recommended Posts

Sveicināti!

 

Ir izveidota lapa https://datatables.net/examples/data_sources/ajax

 

new DataTable('#example', {
    ajax: '../ajax/data/arrays.txt'
});

 

Datu avots ir fails '../ajax/data/arrays.txt'

Faila saturs:

{
  "data": [
    [
      "Tiger Nixon",
      "System Architect",
      "Edinburgh",
      "5421",
      "2011/04/25",
      "$320,800"
    ],
    [
      "Garrett Winters",
      "Accountant",
      "Tokyo",
      "8422",
      "2011/07/25",
      "$170,750"
    ]
 ]
}

 

../ajax/data/arrays.txt' ģenerējās katru dienu no jauna.

 

Rotaļu kaste: https://jsfiddle.net/y7pvetrd/

Pašreizējo index.html faila lastModified atribūtu iegūst ar kodu:

 

Updated: <span id='demo'></span>
	
	<script>
		function myFunction() {
		var x = document.lastModified;
		document.getElementById("demo").innerHTML = new Date(document.lastModified).toLocaleString('en-de', { weekday:"long", year:"numeric", month:"short", day:"numeric", hour:"numeric", minute:"numeric"});
		}

		myFunction()
	</script>

 

Kādā veidā HTML kodā attēlot faila ../ajax/data/arrays.txt' lastModified atribūtu, jo šis fails atjaunojas katru dienu.

Link to comment
Share on other sites

versatile

No pieredzes - prātīgāk ir datos rakstīt iekšā last update laiku, jo gadīsies backup vai kas tāds, un tad visi faili būs vienā dienā modificēti un būs auzas.
Jā, konkrētā gadījumā, iespējams, lieki, bet jāpierod darīt pareizi.

  • Patīk 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...