Hi guys
if I have this code in HTML
how to get the date time from my PC automatically??
FYI: I don’t know how to connect a js file into my index!!
Hi guys
if I have this code in HTML
how to get the date time from my PC automatically??
FYI: I don’t know how to connect a js file into my index!!
You can use the Javascript Date() instance to get the current time.
You can also link to a js file by using the script src tag in your header or body.
This example shows a simple way to use the Date() instance as well as link to external CSS/JS:
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="path/to/css/styles.css">
<script src="path/to/js/scripts.js"></script>
</head>
<body>
<span id="time"></span>
<script>
document.getElementById('time').textContent = new Date();
</script>
</body>
</html>
Coincidentally I made a little function this week that displays today’s date like this: Sunday July 30, 2017.
I like that format on a page. Here it is if you want to try it:
//Today's Date function (Day of week Month Day, Year):
var todayDate = function() {
var months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
];
var weekDays = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
];
var x = new Date();
var day = x.getDate();
var weekday = weekDays[x.getDay()];
var month = months[x.getMonth()];
var year = x.getFullYear();
var today = weekday + " " + month + " " + day + ", " + year;
return today;
};