So, I’m making a website that archives all of Magnus Scheving’s interviews, but most of the interviews are from before 2019. So I put this Javascript code on all pages to tell everyone that I’m updating it regularly and finding new interviews –
<script type="text/JavaScript" language="JavaScript">
<!--
//
// format date as dd-mmm-yy
// example: 12-Jan-99
//
function date_ddmmmyy(date)
{
var d = date.getDate();
var m = date.getMonth() + 1;
var y = date.getYear();
// handle different year values
// returned by IE and NS in
// the year 2000.
if(y >= 2000)
{
y -= 2000;
}
if(y >= 100)
{
y -= 100;
}
// could use splitString() here
// but the following method is
// more compatible
var mmm =
( 1==m)?'Jan':( 2==m)?'Feb':(3==m)?'Mar':
( 4==m)?'Apr':( 5==m)?'May':(6==m)?'Jun':
( 7==m)?'Jul':( 8==m)?'Aug':(9==m)?'Sep':
(10==m)?'Oct':(11==m)?'Nov':'Dec';
return "" +
(d<10?"0"+d:d) + "-" +
mmm + "-" +
(y<10?"0"+y:y);
}
//
// get last modified date of the
// current document.
//
function date_lastmodified()
{
var lmd = document.lastModified;
var s = "Unknown";
var d1;
// check if we have a valid date
// before proceeding
if(0 != (d1=Date.parse(lmd)))
{
s = "" + date_ddmmmyy(new Date(d1));
}
return s;
}
//
// finally display the last modified date
// as DD-MMM-YY
//
document.write(
"This page was updated on " +
date_lastmodified() );
// -->
</script>
I’d be happy with it, but the thing is, it only shows the date you’ve updated it and not the time. Is there any way to add the time? I’d prefer it in AEST time, thanks.
I searched the web for any answers, but they all gave me answers on how to put the ‘last updated DATE’ and not time inside an HTML page
2
Answers
Then display the last modified date and time as DD-MMM-YY HH:MM
You can use some library to convert into timezones
Is it possible these links would be of value?
Getting current date and time in JavaScript
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString
When using JavaScript’s
Date()
, you should get an output in your operating system’s selected time zone.