JavaScript - date methods

revision:


list of date methods and description.

Date() : returns today's date and time.

syntax: new Date(date)

getDate() : returns the day of the month for the specified date according to local time.

syntax:   Date.getDate()

getDay() : returns the day of the week for the specified date according to local time.

syntax:  Date.getDay()

getFullYear() : returns the year of the specified date according to local time.

syntax: Date.getFullYear()

getHours() : returns the hour in the specified date according to local time.

syntax:Date.getHours()

getMilliseconds() : returns the milliseconds in the specified date according to local time.

syntax:Date.getMilliseconds()

getMinutes() : returns the minutes in the specified date according to local time.

syntax: Date.getMinutes()

getMonth() : returns the month in the specified date according to local time.

syntax:Date.getMonth()

getSeconds() : returns the seconds in the specified date according to local time.

syntax:Date.getSeconds()

getTime() : returns the numeric value of the specified date as the number of milliseconds since January 1, 1970, 00:00:00 UTC.

syntax: Date.getTime()

getTimezoneOffset() : returns the time-zone offset in minutes for the current locale.

syntax:Date.getTimezoneOffse()

getUTCDate() : returns the day (date) of the month in the specified date according to universal time.

syntax:Date.getUTCDate()

getUTCDay() : returns the day of the week in the specified date according to universal time.

syntax:Date.getUTCDay()

getUTCFullYear() : returns the year in the specified date according to universal time.

syntax:Date.getUTCFullYear()

getUTCHours() : returns the hours in the specified date according to universal time.

syntax:Date.getUTCHours()

getUTCMilliseconds() : returns the milliseconds in the specified date according to universal time.

syntax:Date.getUTCMilliseconds()

getUTCMinutes() : returns the minutes in the specified date according to universal time.

syntax:Date.getUTCMinutes()

getUTCMonth() : returns the month in the specified date according to universal time.

syntax:Date.getUTCMonth()

getUTCSeconds() : returns the seconds in the specified date according to universal time.

syntax:Date.getUTCSeconds()

getYear() : deprecated - returns the year in the specified date according to local time. Use getFullYear instead.

syntax:Date.getYear()

setDate() : sets the day of the month for a specified date according to local time.

syntax:Date.setDate(day)

setFullYear() : sets the full year for a specified date according to local time.

syntax:Date.setFullYear(year, month, day)

setHours() : sets the hours for a specified date according to local time.

syntax:Date.setHours(hour, min, sec, millisec)

setMilliseconds() : sets the milliseconds for a specified date according to local time.

syntax:Date.setMilliseconds(millisec)

setMinutes() : sets the minutes for a specified date according to local time.

syntax: Date.setMinutes(min, sec, millisec)

setMonth() : sets the month for a specified date according to local time.

syntax:Date.setMonth(month, day)

setSeconds() : sets the seconds for a specified date according to local time.

syntax: Date.setSeconds(sec, millisec)

setTime() : sets the Date object to the time represented by a number of milliseconds since January 1, 1970, 00:00:00 UTC.

syntax:Date.setTime(millisec)

setUTCDate() : sets the day of the month for a specified date according to universal time.

syntax:Date.setUTCDate(day)

setUTCFullYear() : sets the full year for a specified date according to universal time.

syntax: Date.setUTCFullYear(year, month, day

setUTCHours() : sets the hour for a specified date according to universal time.

syntax: Date.setUTCHours(hour, min, sec, millisec)

setUTCMilliseconds() : sets the milliseconds for a specified date according to universal time.

syntax: Date.setUTCMilliseconds(millisec)

setUTCMinutes() : sets the minutes for a specified date according to universal time.

syntax: Date.setUTCMinutes(min, sec, millisec)

setUTCMonth() : sets the month for a specified date according to universal time.

syntax: Date.setUTCMonth(month, day)

setUTCSeconds() : sets the seconds for a specified date according to universal time.

syntax: Date.setUTCSeconds(sec, millisec)

setYear() : deprecated - sets the year for a specified date according to local time. Use setFullYear instead.

syntax:

toDateString() : returns the "date" portion of the Date as a human-readable string.

syntax:Date.toDateString()

toGMTString() : deprecated - converts a date to a string, using the Internet GMT conventions. Use toUTCString instead.

syntax:

toLocaleDateString() : returns the "date" portion of the Date as a string, using the current locale's conventions.

syntax: Date.toLocaleDateString()

toLocaleFormat() : converts a date to a string, using a format string.

syntax: 

toLocaleString() : converts a date to a string, using the current locale's conventions.

syntax: Date.toLocaleString(locales, options)

toLocaleTimeString() : returns the "time" portion of the Date as a string, using the current locale's conventions.

syntax: Date.toLocaleTimeString()

toSource() : returns a string representing the source for an equivalent Date object; you can use this value to create a new object.

syntax:  

toString() : returns a string representing the specified Date object.

syntax:Date.toString()

toTimeString() : returns the "time" portion of the Date as a human-readable string.

syntax:Date.toTimeString()

toUTCString() : converts a date to a string, using the universal time convention.

syntax:Date.toUTCString()

valueOf() : returns the primitive value of a Date object.

syntax:Date.valueOf()

date static methods are invoked through the Date() constructor

Date.parse() : parses a string representation of a date and time and returns the internal millisecond representation of that date.

syntax:Date.parse(datestring)

Date.UTC() : returns the millisecond representation of the specified UTC date and time.

syntax: Date.UTC(year, month, day, hours, minutes, seconds, millisec)

examples:

code:
            <div>
                <p class="spec" id="date1"></p>
                <p class="spec" id="date2"></p>
                <p class="spec" id="date3"></p>
                <p class="spec" id="date4"></p>
                <p class="spec" id="date5"></p>
                <p class="spec" id="date6"></p>
                <p class="spec" id="date7"></p>
                <p class="spec" id="date8"></p>
                <p class="spec" id="date9"></p>
                <p class="spec" id="date10"></p>
                <p class="spec" id="date11"></p>
                <p class="spec" id="date12"></p>
                <p class="spec" id="date13"></p>
                <p class="spec" id="date14"></p>
                <p class="spec" id="date15"></p>
                <p class="spec" id="date16"></p>
                <p class="spec" id="date17"></p>
                <p class="spec" id="date18"></p>
                <p class="spec" id="date19"></p>
                <p class="spec" id="date20"></p>
                <p class="spec" id="date21"></p>
                <p class="spec" id="date22"></p>
                <p class="spec" id="date23"></p>
               
            </div>
            <script>
                const time = new Date();
                document.getElementById("date1").innerHTML = "time() : " + time;
        
                const d = new Date();
                let text = d.constructor;
                document.getElementById("date2").innerHTML = "constuctor : " + text;
                let day = d.getDate();
                document.getElementById("date3").innerHTML = "getDate : " + day;
                let day1 = d.getDay()
                document.getElementById("date4").innerHTML = "getDay : " + day1;
                let year = d.getFullYear();
                document.getElementById("date5").innerHTML = "getFullYear: " + year;
                let hour = d.getHours();
                document.getElementById("date6").innerHTML = "getHours: " + hour;
                let ms = d.getMilliseconds();
                document.getElementById("date7").innerHTML = "getMilliseconds : " + ms;
                let minutes = d.getMinutes();
                document.getElementById("date8").innerHTML = "getMinutes : " + minutes;
                let month = d.getMonth();
                document.getElementById("date9").innerHTML = "getMonth : " + month;
                let seconds = d.getSeconds();
                document.getElementById("date10").innerHTML = "getSeconds : " + seconds;
                let time1 = d.getTime();
                document.getElementById("date11").innerHTML = "getTime : " + time1;
                let diff = d.getTimezoneOffset();
                document.getElementById("date12").innerHTML =  "getTimezoneOffset: " + diff;
                let day2 = d.getUTCDate();
                document.getElementById("date13").innerHTML = "getUTCDate : " + day2;
                let day3 = d.getUTCDay();
                document.getElementById("date14").innerHTML = "getUTCDay : " + day3;
                let year2 = d.getUTCFullYear();
                document.getElementById("date15").innerHTML = "getUTCFullYear : " + year2;
                let hour2 = d.getUTCHours();
                document.getElementById("date16").innerHTML = "getUTCHours : " + hour2;
                let ms2 = d.getUTCMilliseconds();
                document.getElementById("date17").innerHTML = "geUTCtMilliseconds : " + ms2;
                let minutes2 = d.getUTCMinutes();
                document.getElementById("date18").innerHTML = "getUTCMinutes : " + minutes2;
                let month2 = d.getUTCMonth();
                document.getElementById("date19").innerHTML = "getUTCMonth : " + month2;
                let seconds2 = d.getUTCSeconds();
                document.getElementById("date20").innerHTML = "getUTCSeconds : " + seconds2;
                let ms3 = Date.now();
                document.getElementById("date21").innerHTML = "Date.now : " + ms3;
                const dd= new Date();
                dd.setDate(15);
                document.getElementById("date22").innerHTML =  "setDate : " + dd;
                dd.setFullYear(2024)
                document.getElementById("date23").innerHTML = " setFullYear: " + dd;
                
            </script>