Date

3 0 0
                                        

Date - Like a class in java where you can create an object by invoking the keyword new and passing the constructor of the class which is Date without arguments.

syntax:

let obj = new Date();

=================

let dateNow = new Date();

function getDateToday(){

    document.writeln(dateNow);

}

==================

HTML:

getDateToday()

Result:

Sun Aug 28 2022 .....


syntax 2: Passing an timestamp argument

let obj = new Date(24*3600*1000);

timestamp - this is a time converted to milliseconds. Like saying 24 * 3600 * 1000. This is a timestamp for 24 hours converted to milliseconds. This is mathematics. Hours converted to seconds. Then the seconds converted to milliseconds. The result of the above code is Jan 02 1970 because the purpose of the argument was to add the timestamp to the started date which Jan 01 1970. This is the epoch time or the unix time started. There are other syntax for date because this is like a Java constructor polymorphism. Date has functions that can be access through the object you created like obj.getFullYear() or obj.getHours().


Star Note:

Today, this is the first time I used vs code, not the vs community. I normally used intellij, android studio, and also eclipse. Why I included this, vs code has a live preview extension for html. This means that you do not need to keep on pressing run. You can see the changes right away as you program.

Javascript ProgrammingNơi câu chuyện tồn tại. Hãy khám phá bây giờ