Curs Javascript


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.


Metode Getter

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

Metode Setter

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

Metode pentru conversie din obiect Date

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.


Un Test simplu in fiecare zi

HTML
CSS
JavaScript
PHP-MySQL
Engleza
Spaniola
Care tag adauga rand nou in paragraf?
<b> <br> <p>
Prima linie ...<br>
Alta linie...
Ce proprietate CSS seteaza spatiu dintre litere?
text-size word-spacing letter-spacing
#id {
  letter-spacing: 2px;
}
Ce functie obtine accesul la un element HTML cu un anumit ID?
getElementById() getElementsByTagName() createElement()
var elm = document.getElementById("theID");
var content = elm.innerHTML;
alert(content);
Clic pe instructiunea "echo" utilizata corect.
echo "CoursesWeb.net" echo "CoursesWeb.net"; echo ""CoursesWeb.net";
echo "Adresa URL: http://CoursesWeb.net";
Care din urmatoarele expresii cu "paint" (a picta) se foloseste pentru forma Negativa?
will paint not paint have painted
She does not paint that landscape.
- Ea nu picteaza acel peisaj.
Care din urmatoarele expresii cu "cantar" (a canta) se foloseste pentru propozitie Negativa?
ir a cantar cantaba no cantar
Ella no canta esa canciĆ³n.
- Ea nu canta acel cantec.
Metode ale obiectului Date

Last accessed pages

  1. Cursuri si Tutoriale: Engleza, Spaniola, HTML, CSS, Php-Mysql, JavaScript, Ajax (270000)
  2. Exercitii engleza - English Tests and exercises - Grammar (113698)
  3. Sufixele -ful, -less si -ness - ful, less and ness suffixes (17760)
  4. Verbe modale - Modal verbs - CAN, COULD, MAY, MIGHT, MUST (66769)
  5. Jokes - Glume, Bancuri, Humor (2) (16682)

Popular pages this month

  1. Cursuri si Tutoriale: Engleza, Spaniola, HTML, CSS, Php-Mysql, JavaScript, Ajax (1039)
  2. Gramatica limbii engleze - Prezentare Generala (654)
  3. Exercitii engleza - English Tests and exercises - Grammar (595)
  4. Prezentul simplu si continuu - Present Tense Simple and Continuous (475)
  5. Coduri pt culori (396)