Lista cu metode JavaScript utile ale obiectului Date pentru lucru cu data si timp in scripturi JS.
- Metodele Getter preia /citeste datele din obiect, metodele Setter seteaza /redefinesc datele in obiect.
getDate()
- returneaza ziua din luna (intre 1-31).var dt = new Date('Jul 11, 2018 09:25:30'); console.log(dt.getDate()); // 11
getDay()
- returneaza numarul zilei din saptamana (intre 0-6; 0=Duminica, 1=Luni, ... 6=Sambata).const days =['Duminica', 'Luni', 'Marti', 'Miercuri', 'Joi', 'Vineri', 'Sambata']; var dt = new Date('Jul 11, 2018 09:25:30'); let wday = days[dt.getDay()]; console.log(wday); // Miercuri
getFullYear()
- returneaza anul, cu 4 cifre.var dt = new Date('Jul 11, 2018 09:25:30'); console.log(dt.getFullYear()); // 2018
getHours()
- returneaza ora, intre 0 si 23.var dt = new Date('Jul 11, 2018 09:25:30'); console.log(dt.getHours()); // 9
getMilliseconds()
- returneaza milisecundele (0-999).var dt = new Date('Jul 11, 2018 09:25:30'); console.log(dt.getMilliseconds()); // 0
getMinutes()
- returneaza minutele (0-59).var dt = new Date('Jul 11, 2018 09:25:30'); console.log(dt.getMinutes()); // 25
getMonth()
- returneaza numarul lunii (intre 0-11. 0=January, 1=February, ... 11=December).var dt = new Date('Jul 11, 2018 09:25:30'); console.log(dt.getMonth()); // 6
getSeconds()
- returneaza secundele (0-59).var dt = new Date('Jul 11, 2018 09:25:30'); console.log(dt.getSeconds()); // 30
getTime()
- returneaza numarul de milisecunde de la data de referinta 0 (1 Ianuarie 1970) pana la data din obiectul Date.var dt = new Date('Jul 11, 2018 09:25:30'); console.log(dt.getTime()); // 1531290330000
getTimezoneOffset()
- returneaza diferenta de timp (in minute) intre computer si GMT.var dt = new Date('Jul 11, 2018 09:25:30'); console.log(dt.getTimezoneOffset()); // -180 (-3 ore)
getUTCDate()
- returneaza ziua din luna (1-31), in (UTC) timp universal .var dt = new Date('Jul 11, 2018 09:25:30'); console.log(dt.getUTCDate()); // 11
getUTCDay()
- returneaza numarul zilei din saptamana in timp universal (intre 0-6; 0=Duminica, 1=Luni, ... 6=Sambata).const days =['Duminica', 'Luni', 'Marti', 'Miercuri', 'Joi', 'Vineri', 'Sambata']; var dt = new Date('Jul 11, 2018 09:25:30'); let wday = days[dt.getUTCDay()]; console.log(wday); // Miercuri
getUTCFullYear()
- returneaza anul in timp universal, cu 4 cifre.var dt = new Date('Jul 11, 2018 09:25:30'); console.log(dt.getUTCFullYear()); // 2018
getUTCHours()
- returneaza ora in timp universal (0-23).var dt = new Date('Jul 11, 2018 09:25:30'); console.log(dt.getUTCHours()); // 6
getUTCMilliseconds()
- returneaza milisecundele in timp universal (0-999).var dt = new Date('Jul 11, 2018 09:25:30'); console.log(dt.getUTCMilliseconds()); // 0
getUTCMinutes()
- returneaza minutele in timp universal (0-59).var dt = new Date('Jul 11, 2018 09:25:30'); console.log(dt.getUTCMinutes()); // 25
getUTCMonth()
- returneaza numarul lunii in timp universal (intre 0-11. 0=January, 1=February, ... 11=December).var dt = new Date('Jul 11, 2018 09:25:30'); console.log(dt.getUTCMonth()); // 6
getUTCSeconds()
- returneaza secundele in timp universal (0-59).var dt = new Date('Jul 11, 2018 09:25:30'); console.log(dt.getUTCSeconds()); // 30
setDate()
- seteaza ziua din luna (intre 1-31).var dt = new Date('Jul 11, 2018 09:25:30'); dt.setDate(15); console.log(dt.getDate()); // 15
setFullYear()
- seteaza anul, cu 4 cifre.var dt = new Date('Aug 15, 2018 09:25:30'); dt.setFullYear(2019); console.log(dt.getFullYear()); // 2019
setHours()
- seteaza ora, intre 0 si 23.var dt = new Date('Aug 15, 2018 09:25:30'); dt.setHours(16); console.log(dt.getHours()); // 16
setMilliseconds()
- seteaza milisecundele (0-999).var dt = new Date('Aug 15, 2018 09:25:30'); dt.setMilliseconds(234); console.log(dt.getMilliseconds()); // 234
setMinutes()
- seteaza minutele (0-59).var dt = new Date('Aug 15, 2018 09:25:30'); dt.setMinutes(55); console.log(dt.getMinutes()); // 55
setMonth()
- seteaza numarul lunii (intre 0-11. 0=January, 1=February, ... 11=December).var dt = new Date('Aug 15, 2018 09:25:30'); dt.setMonth(4); console.log(dt.getMonth()); // 4
setSeconds()
- seteaza secundele (0-59).var dt = new Date('Aug 15, 2018 09:25:30'); dt.setSeconds(23); console.log(dt.getSeconds()); // 23
setTime()
- seteaza numarul de milisecunde de la data de referinta 0 (1 Ianuarie 1970) pana la data din obiectul Date.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()
- seteaza ziua din luna (1-31), in (UTC) timp universal.var dt = new Date('Aug 15, 2018 09:25:30'); dt.setUTCDate(18); console.log(dt.getUTCDate()); // 18
setUTCFullYear()
- seteaza anul in timp universal, cu 4 cifre.var dt = new Date('Aug 15, 2018 09:25:30'); dt.setUTCFullYear(2019); console.log(dt.getUTCFullYear()); // 2019
setUTCHours()
- seteaza ora in timp universal (0-23).var dt = new Date('Aug 15, 2018 09:25:30'); dt.setUTCHours(16); console.log(dt.getUTCHours()); // 16
setUTCMilliseconds()
- seteaza milisecundele in timp universal (0-999).var dt = new Date('Aug 15, 2018 09:25:30'); dt.setUTCMilliseconds(345); console.log(dt.getUTCMilliseconds()); // 345
setUTCMinutes()
- seteaza minutele in timp universal (0-59).var dt = new Date('Aug 15, 2018 09:25:30'); dt.setUTCMinutes(22); console.log(dt.getUTCMinutes()); // 22
setUTCMonth()
- seteaza numarul lunii in timp universal (intre 0-11. 0=January, 1=February, ... 11=December).var dt = new Date('Aug 15, 2018 09:25:30'); dt.setUTCMonth(8); console.log(dt.getUTCMonth()); // 8
setUTCSeconds()
- seteaza secundele in timp universal (0-59).var dt = new Date('Aug 15, 2018 09:25:30'); dt.setUTCSeconds(45); console.log(dt.getUTCSeconds()); // 45
toDateString()
- returneaza un sir cu portiunea de data: 'Nume_zi Luna Nr_zi An'.var dt = new Date('Jun 20, 2018 13:30:45'); console.log(dt.toDateString()); // Wed Jun 20 2018
toJSON()
- returneaza un sir cu obiectul Date specificat.var dt = new Date('Jun 20, 2018 13:30:45'); console.log(dt.toJSON()); // 2018-06-20T10:30:45.000Z
toString()
- returneaza un sir reprezentand obiectul Date specificat.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()
- returneaza un sir cu portiunea de timp din obiectul Date specificat.var dt = new Date('Jun 20, 2018 13:30:45'); console.log(dt.toTimeString()); // 13:30:45 GMT+0300 (GTB Daylight Time)
- O lista cu metodele obiectului Date gasiti la MDN: Date JavaScript.
Prima linie ...<br> Alta linie...
#id { letter-spacing: 2px; }
var elm = document.getElementById("theID"); var content = elm.innerHTML; alert(content);
echo "Adresa URL: http://CoursesWeb.net";
She does not paint that landscape. - Ea nu picteaza acel peisaj.
Ella no canta esa canciĆ³n. - Ea nu canta acel cantec.