js method to get the current system date and time


This article illustrates how js gets the date and time of the current system. Share to everybody for everybody reference. Specific implementation methods are as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js Time to show </title>
<script>
var curr_time = new Date();
var strDate = curr_time.getYear()+" years ";
strDate += curr_time.getMonth()+1+" month ";
strDate += curr_time.getDate()+" day ";
strDate += curr_time.getHours()+":";
strDate += curr_time.getMinutes()+":";
strDate += curr_time.getSeconds();
document.write(strDate);

var curr_time = new Date();
with(curr_time)
{
// Define the variable and assign it to the current year, followed by the Chinese character "year"
var strDate = getYear()+1900+" years ";
// Take the current month. Notice that the months from 0 So let's start, so let's add 1 , followed by the Chinese character "month" logo
strDate +=getMonth()+1+" month ";
strDate +=getDate()+" day "; // Take the current date, followed by the Chinese character "day" logo
strDate +=getHours()+":"; // Take the current hour
strDate +=getMinutes()+":"; // Take current minute
strDate +=getSeconds(); // Take the current number of seconds
alert(strDate); // Results output
}
</script>
</head>
<body>
</body>
</html>

Hopefully, this article has been helpful in your javascript programming.