HTML 5 : Source code to display Date and Time :
Solved/Closed
Arno59
Posted messages
4603
Registration date
Status
Contributor
Last intervention
-
jordane45 Posted messages 30426 Registration date Status Moderator Last intervention -
jordane45 Posted messages 30426 Registration date Status Moderator Last intervention -
Hello,
I am currently redoing a website in xHTML.
Some scripts were in Javascript (displaying the date and time)
Thursday, May 12, 2016, it is 2:43 PM.
Is it possible to do the same in HTML 5?
What is the source?
Thank you in advance
Configuration: Operating systems:
- Linux: Debian 8, Gentoo 20150505, Fedora 23, Ubuntu 15.10
--
Free "Open source" software responds to the consumer's freedom of choice and societal digital innovation in the 21st century.
I am currently redoing a website in xHTML.
Some scripts were in Javascript (displaying the date and time)
Thursday, May 12, 2016, it is 2:43 PM.
script type="text/javascript">
var d = new Date()
var j = d.getDate()
var m = d.getMonth()
var y = d.getFullYear()
var h = d.getHours()
var mn = d.getMinutes()
Is it possible to do the same in HTML 5?
What is the source?
Thank you in advance
Configuration: Operating systems:
- Linux: Debian 8, Gentoo 20150505, Fedora 23, Ubuntu 15.10
--
Free "Open source" software responds to the consumer's freedom of choice and societal digital innovation in the 21st century.
3 answers
-
Hello,
Thank you for your response.
The script regarding Javascript was as follows:
<script language = "JavaScript" type = "text/javascript">
var d = new Date()
var j = d.getDate()
var m = d.getMonth() + 1
var y = d.getYear()
if (y < 999)
y += 1900;
var h = d.getHours()
var mn = d.getMinutes()
var mois, jour;
var dayNames = new
Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
if (m == 1)
mois = " January";
else if (m == 2)
mois = " February";
else if (m == 3)
mois = " March";
else if (m == 4)
mois = " April";
else if (m == 5)
mois = " May";
else if (m == 6)
mois = " June";
else if (m == 7)
mois = " July";
else if (m == 8)
mois = " August";
else if (m == 9)
mois = " September";
else if (m == 10)
mois = " October";
else if (m == 11)
mois = " November";
else if (m == 12)
mois = " December";
if (j == 1)
jour = "1st"
else
jour = j;
// Test to determine the formula to use
if (h >= 18)
document.write("Good evening");
else
document.write("Good morning");
document.write(" and welcome to my site. ")
document.write("Today is " + dayNames[d.getDay()] + " " + jour + " " + mois + " " + y + ", ")
document.write("it is " + h)
if (h < 2)
document.write(" hour ")
else
document.write(" hours ")
document.write(mn)
if (mn < 2)
document.write(" minute.")
else
document.write(" minutes.")
</script>
Is this script still correct, as it is a few years old?
Thank you in advance
--
Free software "Open source" responds to the consumer's freedom of choice and societal digital innovation in the 21st century.