-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateInAFormat.js
More file actions
28 lines (22 loc) · 762 Bytes
/
DateInAFormat.js
File metadata and controls
28 lines (22 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//* Write a JavaScript program to get the current date.
//* mm-dd-yyyy, mm/dd/yyyy or dd-mm-yyyy, dd/mm/yyyy
//? Date class object to access the date and time
var d = new Date();
//! 1. Get the current month
var mm = d.getMonth();
//! 2. Get the current date of today
var dd = d.getDay();
//! 3. Get the current month
var yyyy = d.getFullYear();
//? 1. First format to print the current date
//* mm-dd-yyyy
console.log(mm + "-" + dd + "-" + yyyy);
//? 2. Second format to print the current date
//* mm/dd/yyyy
console.log(mm + "/" + dd + "/" + yyyy);
//? 3. Third format to print the current date
//* dd-mm-yyyy
console.log(dd + "-" + mm + "-" + yyyy);
//? 4. Fourth format to print the current date
//* dd/mm/yyyy
console.log(dd + "/" + mm + "/" + yyyy);