Jump to content
David Pintassilgo

[Javascript] Data/hora Última Modificação

Recommended Posts

David Pintassilgo

Aproveitando a dica da tofas, aqui fica como meter automaticamente na página a última edição do ficheiro:

<SCRIPT LANGUAGE="Javascript">
   document.write("Última Actualização a: " + document.lastModified);
</SCRIPT>


cool stuffs to check.

http://blog.zxcoders.com//

Share this post


Link to post
Share on other sites
David Pintassilgo

um "upgrade" do Pedantilva

<SCRIPT LANGUAGE="JavaScript">
var data_i = new Date (document.lastModified);
var data_f = "Última Actualização a: ";
data_f += data_i.getDate();
data_f += "-"; 
data_f += data_i.getMonth() + 1;
data_f += "-"; 
data_f += data_i.getFullYear();
document.write(data_f);
<SCRIPT>


cool stuffs to check.

http://blog.zxcoders.com//

Share this post


Link to post
Share on other sites
David Pintassilgo

e outro do SacoPlastico

<SCRIPT LANGUAGE="JavaScript">
   document.write(document.lastModified[3]);
           document.write(document.lastModified[4]);
           document.write(document.lastModified[2]);
           document.write(document.lastModified[0]);
           document.write(document.lastModified[1]);
           document.write(document.lastModified[5]);
           document.write(document.lastModified[6]);
           document.write(document.lastModified[7]);
</SCRIPT>


cool stuffs to check.

http://blog.zxcoders.com//

Share this post


Link to post
Share on other sites
saramgsilva

actualização

Já encontrei um que acho que deve funcionar:

<SCRIPT LANGUAGE="JavaScript">
   function lastMod()
{
var x = new Date (document.lastModified);
Modif = new Date(x.toGMTString());
Year = takeYear(Modif);
Month = Modif.getMonth();
Day = Modif.getDate();
Mod = (Date.UTC(Year,Month,Day,0,0,0))/86400000;
x = new Date();
today = new Date(x.toGMTString());
Year2 = takeYear(today);
Month2 = today.getMonth();
Day2 = today.getDate();
now = (Date.UTC(Year2,Month2,Day2,0,0,0))/86400000;
daysago = now - Mod;
if (daysago < 0) return '';
unit = 'dias';
if (daysago > 730)
{
	daysago = Math.floor(daysago/365);
	unit = 'anos';
}
else if (daysago > 60)
{
	daysago = Math.floor(daysago/30);
	unit = 'meses';
}
else if (daysago > 14)
{
	daysago = Math.floor(daysago/7);
	unit = 'semanas'
}
var towrite = 'Última actualização: ';
if (daysago == 0) towrite += 'hoje.';
else if (daysago == 1) towrite += 'ontem.';
else towrite += ' à ' + daysago + ' ' + unit + ' ago';
return towrite;
}


function takeYear(theDate)
{
x = theDate.getYear();
var y = x % 100;
y += (y < 38) ? 2000 : 1900;
return y;
} document.write(lastMod());
</SCRIPT>

retirado de:

http://www.quirksmode.org/js/lastmod.html

pois o seguinte pareceu que nao fazia o que se queria  ( pareceu que escrevia a data do proprio dia...mesmo nao havendo mudanças... )

um "upgrade" do Pedantilva

<SCRIPT LANGUAGE="JavaScript">
var data_i = new Date (document.lastModified);
var data_f = "Última Actualização a: ";
data_f += data_i.getDate();
data_f += "-"; 
data_f += data_i.getMonth() + 1;
data_f += "-"; 
data_f += data_i.getFullYear();
document.write(data_f);
<SCRIPT>

Share this post


Link to post
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

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.