Date And math in JavaScript
Date
In java script Date is trite as Function , or you say method also you can say Object.
Date() method gives you current date , with current time. Remember that It gives Date and Time based on your Operating system(OS). if your os issues in date and time , then this method not work properly.
Syntax of Date()
const now = new Date()
console.log(now);
Methos of Date
There is Many Method for Access particulars Day, Year, Month, Hour, Minitus, Date or etc......
Const now = new Date()
getFullYear( )
This method return only year , and removing all other things. It is built in method of Date that provide current year. following is the example of this method.
Const now = new Date()
console.log(now.getFullYear())
getMonth( )
This method return only month , and removing all other things. It is built in method of Date that provide current month. following is the example of this method.
Const now = new Date()
console.log(now.getMonth())
getDay( )
This method return only Day , is starting from 0 means 0 refer as Sunday then 1 is refers as Monday then up to 6 is refer as Saturday , and removing all other things. It is built in method of Date that provide current Day. following is the example of this method.
Const now = new Date()
console.log(now.getDay())
getTime( )
This method return only Current Time , and removing all other things. It is built in method of Date that provide current time. following is the example of this method.
Const now = new Date()
console.log(now.getTime())
getHours( )
This method return only Hours which is running now , is starting from 0 means 0 refer as 00:00 to 00:59 then 1 is refers as 1:00 to 1:59 then up to 23 is refer as 23:00 to 23:59, and removing all other things. It is built in method of Date that provide current Hour. following is the example of this method.
Const now = new Date()
console.log(now.getHours())
getMinutes( )
This method return only Minute , and removing all other things. It is built in method of Date that provide current Minute. following is the example of this method.
Const now = new Date()
console.log(now.getMinteus())
getSeconds( )
This method return only second , It gives like millisecond's, and removing all other things. It is built in method of Date that provide current second. following is the example of this method.
Const now = new Date()
console.log(now.getSeconds())
Math
In java script Math is trite as Function , or you say method also you can say Object.
syntax of math
const PI = Math.pi;
console.log(PI);
Methos of Math
round
console.log(math.round(3.444));
floor
console.log(math.floor(3.444));
ceil
console.log(math.ceil(3.444));
max
console.log(math.max(3,10,20,3,4,5));
min
console.log(math.floor(10,20,30,5,4,1));
random
Range between 0 - 0.9999999999
console.log(math.random());
console.log(math.random() * 10);
console.log(math.random() * 50);
Power
console.log(math.pow(2,3));
Log
console.log(math.log(2));
Conclusion
This guide explains JavaScript's `Date` and `Math` objects, covering key methods such as `getFullYear()`, `getMonth()`, `getDay()`, and `getTime()` for dates, and `round()`, `floor()`, `ceil()`, `max()`, `min()`, `random()`, and `pow()` for mathematical operations. Examples are provided for each method to demonstrate their usage and output.