WebSite X5Help Center

 
Steve P.
Steve P.
User

Javascript for current date  en

Autor: Steve P.
Besucht 1296, Followers 1, Geteilt 0  

Hi All

Brand new to X5 and beginning toget my head around it having moved from Serif's WebPlus and Xara Web Design Pro. I want to add a bit of code to the header (or footer that shows the current date in the format....

Wednesday, 21 October, 2020

The code that I used on my previous site went like this...

=============

<style>
.mydate {
font: 16px arial;
color: white;
}
</style>
<SCRIPT LANGUAGE="Javascript"><!--

// Get today's current date.
var now = new Date();

// Array list of days.
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

// Array list of months.
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

// Calculate the number of the current day in the week.
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

// Calculate four digit year.
function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;
}

// Join it all together
today = days[now.getDay()] + ", " +
months[now.getMonth()] + " " +
date + ", " +
(fourdigits(now.getYear())) ;

// Print out the data.
document.write('<span class="mydate">' + today + '</span>');
//--></SCRIPT>

========

I'm not a coding expert, and I downloaded the script many years ago for free. It worked fine on my old site, but when I add it to the 'expert' section of an html code block, nothing shows up at all on my page.

I suspect it's more a fundamental error my ME rather than the script, but can someone point me in the right direction. Ideally, I'm not looking for an alternative, just an indication as to why it's not working for me.

Thank you

Steve

Gepostet am
3 ANTWORTEN - 2 NüTZLICH
Paul M.
Paul M.
Moderator

Hello Steve,

You'd need to separate the CSS and JavaScript portions of your code.

So insert the following code in the main body of the HTML Object:

<SCRIPT LANGUAGE="Javascript"><!--

// Get today's current date.
var now = new Date();

// Array list of days.
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

// Array list of months.
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

// Calculate the number of the current day in the week.
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

// Calculate four digit year.
function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;
}

// Join it all together
today = days[now.getDay()] + ", " +
months[now.getMonth()] + " " +
date + ", " +
(fourdigits(now.getYear())) ;

// Print out the data.
document.write('<span class="mydate">' + today + '</span>');
//--></SCRIPT>

And then put this part in the 'Expert' tab under 'CSS Code':

<style>
.mydate {
font: 16px arial;
color: white;
}
</style>

Kind regards,

Paul

Search the WebSite X5 Help Center

Mehr lesen
Gepostet am von Paul M.
 ‪ KolAsim ‪ ‪
 ‪ KolAsim ‪ ‪
Moderator

... adopting the "inline" style, you can simplify using this single code, to be pasted into any HTML Code Object of the page:

<script>
var now = new Date();
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;}
today = days[now.getDay()] + ", " + months[now.getMonth()] + " " + date + ", " + (fourdigits(now.getYear())) ;
document.write('<span style="font: 22px arial; color: red;font-weight: bold;" >' + today + '</span>');
</script>

...

...!... font: 22px arial; color: red; font-weight: bold;    ...!... customizable ...!...

.

ciao

.

Mehr lesen
Gepostet am von  ‪ KolAsim ‪ ‪
Steve P.
Steve P.
User
Autor

Thanks Guys. Really impressed with the quick replies on here! THANK YOU!

Steve

Mehr lesen
Gepostet am von Steve P.