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 este element de tip bloc?
<div> <img> <span>
<div>Web Programming and Development</div>
Care cod CSS afiseaza textul subliniat?
font-style: italic; text-decoration: underline; font-weight: 500;
h2 {
  text-decoration: underline;
}
Clic pe functia JavaScript care apeleaza o alta functie dupa un anumit timp.
insertBefore() setTimeout() querySelector()
function someFunction() { alert("CoursesWeb.net"); }
setTimeout("someFunction()", 2000);
Clic pe instructiunea care returneaza numarul total de elemente dintr-un array asociativ.
count($array) count($array, 1) strlen()
$food =["fruits" =>["banana", "mar"), "veggie" =>["ceapa", "rosie"));
$nr_food = count($food, 1);
echo $nr_food;       // 6
Indicati Viitorul Perfect la negativ al verbului din paranteze, in propozitia: "The child (to not play) by Sunday".
has't played haven't been playing will haven't played
The child will haven't played by Sunday.
- Copilul nu s-ar fi jucat pana duminica.
Indicati Viitorul Perfect pentru verbul "contar" (a povesti) la forma "Él".
habrá contado va a contar contaba
Él no habrá contado el cuento.
- El nu ar fi spus povestea.
Metode ale obiectului Date

Last accessed pages

  1. Variabile si referinte in functii (1738)
  2. Pronumele in limba engleza - Pronouns (54092)
  3. Verbe - Exercitii si teste engleza incepatori (26549)
  4. Exercitii engleza - English Tests and exercises - Grammar (114196)
  5. Cursuri limba engleza gratuite si lectii online (64677)

Popular pages this month

  1. Cursuri si Tutoriale: Engleza, Spaniola, HTML, CSS, Php-Mysql, JavaScript, Ajax (785)
  2. Exercitii engleza - English Tests and exercises - Grammar (354)
  3. Coduri pt culori (338)
  4. Gramatica limbii engleze - Prezentare Generala (326)
  5. Cursuri limba engleza gratuite si lectii online (321)