List with JavaScript methods of the Date object, useful to work with date and time in JS scripts.
- The Getter gets /reads data from object; the Setter methods sets /redefines datas in object.


Getter Methods

getDate() - returns the day of the month based on the viewer's local time (1-31).
var dt = new Date('Jul 11, 2018 09:25:30');
console.log(dt.getDate()); // 11
getDay() - returns the day of the week (0-6).
const days =['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

var dt = new Date('Jul 11, 2018 09:25:30');
let wday = days[dt.getDay()];

console.log(wday); // Wednesday
getFullYear() - the full year based on the viewer's local time (four digits).
var dt = new Date('Jul 11, 2018 09:25:30');
console.log(dt.getFullYear()); // 2018
getHours() - returns the number of hour, based on the viewer's local time (0-23).
var dt = new Date('Jul 11, 2018 09:25:30');
console.log(dt.getHours()); // 9
getMilliseconds() - the number of milliseconds into the current second in Coordinated Universal Time (0-999).
var dt = new Date('Jul 11, 2018 09:25:30');
console.log(dt.getMilliseconds()); // 0
getMinutes() - returns the minutes (from 0-59).
var dt = new Date('Jul 11, 2018 09:25:30');
console.log(dt.getMinutes()); // 25
getMonth() - returns the month (0-11).
var dt = new Date('Jul 11, 2018 09:25:30');
console.log(dt.getMonth()); // 6
getSeconds() - returns the seconds (from 0 to 59).
var dt = new Date('Jul 11, 2018 09:25:30');
console.log(dt.getSeconds()); // 30
getTime() - the number of milliseconds since 1/1/1970.
var dt = new Date('Jul 11, 2018 09:25:30');
console.log(dt.getTime()); // 1531290330000
getTimezoneOffset() - returns the time difference between GMT (Greenwich Mean Time) and local time (in minutes).
var dt = new Date('Jul 11, 2018 09:25:30');
console.log(dt.getTimezoneOffset()); // -180 (-3 ore)
getUTCDate() - the day of the month in UTC (Coordinated Universal Time) (1-31).
var dt = new Date('Jul 11, 2018 09:25:30');
console.log(dt.getUTCDate()); // 11
getUTCDay() - returns the day of the week, according to universal time (0-6).
const days =['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

var dt = new Date('Jul 11, 2018 09:25:30');
let wday = days[dt.getUTCDay()];

console.log(wday); // Wednesday
getUTCFullYear() - the full year in UTC (Coordinated Universal Time) (four digits).
var dt = new Date('Jul 11, 2018 09:25:30');
console.log(dt.getUTCFullYear()); // 2018
getUTCHours() - returns the hour, according to universal time (0-23).
var dt = new Date('Jul 11, 2018 09:25:30');
console.log(dt.getUTCHours()); // 6
getUTCMilliseconds() - the number of milliseconds into the current second in Coordinated Universal Time (0-999).
var dt = new Date('Jul 11, 2018 09:25:30');
console.log(dt.getUTCMilliseconds()); // 0
getUTCMinutes() - the number of minutes, in UTC (Coordinated Universal Time) (0-59).
var dt = new Date('Jul 11, 2018 09:25:30');
console.log(dt.getUTCMinutes()); // 25
getUTCMonth() - the number of months into the current year in UTC (Coordinated Universal Time) (0-11).
var dt = new Date('Jul 11, 2018 09:25:30');
console.log(dt.getUTCMonth()); // 6
getUTCSeconds() - the number of seconds in Coordinated Universal Time (0-59).
var dt = new Date('Jul 11, 2018 09:25:30');
console.log(dt.getUTCSeconds()); // 30

Setter Methods

setDate() - sets the day of the month for an instance of the Date object (1-31).
var dt = new Date('Jul 11, 2018 09:25:30');
dt.setDate(15);
console.log(dt.getDate()); // 15
setFullYear() - sets the year, according to local time, and returns the new time in milliseconds.
var dt = new Date('Aug 15, 2018 09:25:30');
dt.setFullYear(2019);
console.log(dt.getFullYear()); // 2019
setHours() - sets the hours for an instance of the Date object (0-23) .
var dt = new Date('Aug 15, 2018 09:25:30');
dt.setHours(16);
console.log(dt.getHours()); // 16
setMilliseconds() - sets milliseconds (0-999).
var dt = new Date('Aug 15, 2018 09:25:30');
dt.setMilliseconds(234);
console.log(dt.getMilliseconds()); // 234
setMinutes() - sets minutes (0-59).
var dt = new Date('Aug 15, 2018 09:25:30');
dt.setMinutes(55);
console.log(dt.getMinutes()); // 55
setMonth() - sets the month for an instance of the Date object (from 0-11; 0=January, 1=February).
var dt = new Date('Aug 15, 2018 09:25:30');
dt.setMonth(4);
console.log(dt.getMonth()); // 4
setSeconds() - sets seconds (0-59).
var dt = new Date('Aug 15, 2018 09:25:30');
dt.setSeconds(23);
console.log(dt.getSeconds()); // 23
setTime() - sets the time (in milliseconds since January 1, 1970, at midnight).
var dt = new Date('Aug 15, 2018 09:25:30');
dt.setTime(1541808500 *1000);
document.write(dt);
// Sat Nov 10 2018 02:08:20 GMT+0200 (GTB Standard Time)
setUTCDate() - sets the day of the month, according to universal time (1-31).
var dt = new Date('Aug 15, 2018 09:25:30');
dt.setUTCDate(18);
console.log(dt.getUTCDate()); // 18
setUTCFullYear() - sets the full year in Coordinated Universal Time (four digits).
var dt = new Date('Aug 15, 2018 09:25:30');
dt.setUTCFullYear(2019);
console.log(dt.getUTCFullYear()); // 2019
setUTCHours() - sets the hour, according to universal time (0-23).
var dt = new Date('Aug 15, 2018 09:25:30');
dt.setUTCHours(16);
console.log(dt.getUTCHours()); // 16
setUTCMilliseconds() - sets the milliseconds, according to universal time (0-999).
var dt = new Date('Aug 15, 2018 09:25:30');
dt.setUTCMilliseconds(345);
console.log(dt.getUTCMilliseconds()); // 345
setUTCMinutes() - sets the minutes, according to universal time (0-59).
var dt = new Date('Aug 15, 2018 09:25:30');
dt.setUTCMinutes(22);
console.log(dt.getUTCMinutes()); // 22
setUTCMonth() - sets the month, according to universal time (0-11).
var dt = new Date('Aug 15, 2018 09:25:30');
dt.setUTCMonth(8);
console.log(dt.getUTCMonth()); // 8
setUTCSeconds() - sets the seconds, according to universal time (0-59).
var dt = new Date('Aug 15, 2018 09:25:30');
dt.setUTCSeconds(45);
console.log(dt.getUTCSeconds()); // 45

Methods for Conversion from Date Object

toDateString() - returns the date portion of a Date object in human readable form in American English: 'Day_name Month Nr_day Year'.
var dt = new Date('Jun 20, 2018 13:30:45');
console.log(dt.toDateString()); // Wed Jun 20 2018
toJSON() - returns a string with the specified Date object.
var dt = new Date('Jun 20, 2018 13:30:45');
console.log(dt.toJSON()); // 2018-06-20T10:30:45.000Z
toString() - returns a string that represents the specified Date object.
var dt = new Date('Jun 20, 2018 13:30:45');
console.log(dt.toString());
// Wed Jun 20 2018 13:30:45 GMT+0300 (GTB Daylight Time)
toTimeString() - returns the time portion of a Date object.
var dt = new Date('Jun 20, 2018 13:30:45');
console.log(dt.toTimeString()); // 13:30:45 GMT+0300 (GTB Daylight Time)

- A list with Date object methods to MDN: Date JavaScript.


Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag is used in <table> to create table header cell?
<thead> <th> <td>
<table><tr>
  <th>Title 1</th>
  <th>Title 2</th>
</tr></table>
Which CSS property sets the distance between lines?
line-height word-spacing margin
.some_class {
  line-height: 150%;
}
Which function opens a new browser window.
alert() confirm() open()
document.getElementById("id_button").onclick = function(){
  window.open("http://coursesweb.net/");
}
Indicate the PHP function that returns an array with names of the files and folders inside a directory.
mkdir() scandir() readdir()
$ar_dir = scandir("dir_name");
var_export($ar_dir);
Methods of the Date object

Last accessed pages

  1. PHP PDO - exec (INSERT, UPDATE, DELETE) MySQL (42028)
  2. Output or Force Download MP3 with PHP (1174)
  3. PHP-MySQL free course, online tutorials PHP MySQL code (46636)
  4. Insert, Select and Update NULL value in MySQL (27461)
  5. Create simple Website with PHP (19664)

Popular pages this month

  1. Read Excel file data in PHP - PhpExcelReader (566)
  2. PhpSpreadsheet - Read, Write Excel and LibreOffice Calc files (487)
  3. Register and show online users and visitors (402)
  4. Get Attribute (ID, Class, Name, Title, Src) with jQuery (395)
  5. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (357)