How To Get Current Date In Javascript?

Jul 15, 2021 . Admin

Hello Friends, Now let's see example of how to use javascript get current date example. We will use how to use if get current date in javascript. Here you will learn how to use javascript get current date. This is a short guide on get current date. Let's get started with how to get current date in javascript. Here i will give you many example how you can check javascript get current date. Example: 1
<!DOCTYPE HTML>
<html>
	<head>
		<title>JavaScript How to get current formatted date dd/mm/yyyy</title>
		<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
	</head>
	<body id="body" class="bg-dark">
		<div class="container mt-5">
			<div class="row">
				<div class="col-md-6 offset-md-3">
					<div class="card">
						<div class="card-header">
							<h5>How To Get Current Date In Javascript?</h5>
						</div>
						<div class="card-body">
							<p id="stud"></p>
							<button onclick="timeform()" class="btn btn-primary mb-2">get Date</button>
							<h5 id="test" class="text-danger"></h5>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script>
			var sub = document.getElementById("stud");
			var sup = document.getElementById("test");
			var today = new Date();
			sub.innerHTML = today;
			var dd = today.getDate();
			var mm = today.getMonth() + 1;

			var yyyy = today.getFullYear();
			if (dd < 10) {
				dd = '0' + dd;
			}
			if (mm < 10) {
				mm = '0' + mm;
			}
			var today = dd + '/' + mm + '/' + yyyy;

			function timeform() {
				sup.innerHTML = today;
			}
		</script>
	</body>
</html>
Output:
Fri Jul 02 2021 11:21:48 GMT+0530 (India Standard Time)
02/07/2021
Example: 2
<html> 
	<head>
		<title></title>
		<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
	</head>
	<body id="body" class="bg-dark">
		<div class="container mt-5">
			<div class="row">
				<div class="col-md-6 offset-md-3">
					<div class="card">
						<div class="card-header">
							<h5>How To Get Current Date In Javascript?</h5>
						</div>
						<div class="card-body">
							<p id="stud"></p>
							<button onclick="cmp()" class="btn btn-primary mb-2">get Date</button>
							<h5 id="test" class="text-danger"></h5>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script>
			var sub = document.getElementById("stud");
			var sup = document.getElementById("test");
			var today = new Date();
			sub.innerHTML = today;

			function cmp() {
				var date = today.toJSON().slice(0, 10);
				var nDate = date.slice(8, 10) + '/' 
					+ date.slice(5, 7) + '/' 
					+ date.slice(0, 4);
				sup.innerHTML = nDate;
			}
		</script>
	</body>
</html>
Output:
Fri Jul 02 2021 11:21:51 GMT+0530 (India Standard Time)
02/07/2021

It will help you....

#Javascript