|
1 | | -# Date and time |
| 1 | +# Data și ora |
2 | 2 |
|
3 | | -Let's meet a new built-in object: [Date](mdn:js/Date). It stores the date, time and provides methods for date/time management. |
| 3 | +Să cunoaștem un nou obiect încorporat: [Date](mdn:js/Date). Acesta stochează data, ora și oferă metode de administrare a datei/orei. |
4 | 4 |
|
5 | | -For instance, we can use it to store creation/modification times, to measure time, or just to print out the current date. |
| 5 | +De exemplu, îl putem utiliza pentru a stoca timpul de creare/modificare, pentru a măsura timpul, sau pur și simplu pentru a imprima data curentă. |
6 | 6 |
|
7 | | -## Creation |
| 7 | +## Creare |
8 | 8 |
|
9 | | -To create a new `Date` object call `new Date()` with one of the following arguments: |
| 9 | +Pentru a crea un nou obiect `Date` apelați `new Date()` cu unul dintre următoarele argumente: |
10 | 10 |
|
11 | 11 | `new Date()` |
12 | | -: Without arguments -- create a `Date` object for the current date and time: |
| 12 | +: Fără argumente -- creează un obiect `Date` pentru data și ora curentă: |
13 | 13 |
|
14 | 14 | ```js run |
15 | 15 | let now = new Date(); |
16 | | - alert( now ); // shows current date/time |
| 16 | + alert( now ); // afișează data/ora curentă |
17 | 17 | ``` |
18 | 18 |
|
19 | | -`new Date(milliseconds)` |
20 | | -: Create a `Date` object with the time equal to number of milliseconds (1/1000 of a second) passed after the Jan 1st of 1970 UTC+0. |
| 19 | +`new Date(milisecunde)` |
| 20 | +: Creează un obiect `Date` cu timpul egal cu numărul de milisecunde (1/1000 dintr-o secundă) care au trecut de la 1 ianuarie 1970 UTC+0. |
21 | 21 |
|
22 | 22 | ```js run |
23 | | - // 0 means 01.01.1970 UTC+0 |
| 23 | + // 0 înseamnă 01.01.1970 UTC+0 |
24 | 24 | let Jan01_1970 = new Date(0); |
25 | 25 | alert( Jan01_1970 ); |
26 | 26 |
|
27 | | - // now add 24 hours, get 02.01.1970 UTC+0 |
| 27 | + // acum adaugă 24 de ore, get 02.01.1970 UTC+0 |
28 | 28 | let Jan02_1970 = new Date(24 * 3600 * 1000); |
29 | 29 | alert( Jan02_1970 ); |
30 | 30 | ``` |
31 | 31 |
|
32 | | - An integer number representing the number of milliseconds that has passed since the beginning of 1970 is called a *timestamp*. |
| 32 | + Un număr întreg care reprezintă numărul de milisecunde care au trecut de la începutul anului 1970 se numește *timestamp*. |
33 | 33 |
|
34 | | - It's a lightweight numeric representation of a date. We can always create a date from a timestamp using `new Date(timestamp)` and convert the existing `Date` object to a timestamp using the `date.getTime()` method (see below). |
| 34 | + Este o reprezentare numerică ușoară a unei date. Putem oricând să creăm o dată dintr-un timestamp folosind `new Date(timestamp)` și să convertim obiectul `Date` existent într-un timestamp folosind metoda `date.getTime()` (a se vedea mai jos). |
35 | 35 |
|
36 | | - Dates before 01.01.1970 have negative timestamps, e.g.: |
| 36 | + Datele anterioare 01.01.1970 au timestamp-uri negative, e.g.: |
37 | 37 | ```js run |
38 | 38 | // 31 Dec 1969 |
39 | 39 | let Dec31_1969 = new Date(-24 * 3600 * 1000); |
40 | 40 | alert( Dec31_1969 ); |
41 | 41 | ``` |
42 | 42 |
|
43 | | -`new Date(datestring)` |
44 | | -: If there is a single argument, and it's a string, then it is parsed automatically. The algorithm is the same as `Date.parse` uses, we'll cover it later. |
| 43 | +`new Date(șir de date)` |
| 44 | +: Dacă există un singur argument, și acesta este un șir de caractere, atunci acesta este parsat automat. Algoritmul este același pe care îl folosește `Date.parse`, îl vom acoperi mai târziu. |
45 | 45 |
|
46 | 46 | ```js run |
47 | 47 | let date = new Date("2017-01-26"); |
48 | 48 | alert(date); |
49 | | - // The time is not set, so it's assumed to be midnight GMT and |
50 | | - // is adjusted according to the timezone the code is run in |
51 | | - // So the result could be |
| 49 | + // Ora nu este setată, așa că se presupune că este miezul nopții GMT și |
| 50 | + // este ajustată în funcție de fusul orar în care este rulat codul |
| 51 | + // Astfel rezultatul ar putea fi |
52 | 52 | // Thu Jan 26 2017 11:00:00 GMT+1100 (Australian Eastern Daylight Time) |
53 | | - // or |
| 53 | + // sau |
54 | 54 | // Wed Jan 25 2017 16:00:00 GMT-0800 (Pacific Standard Time) |
55 | 55 | ``` |
56 | 56 |
|
|
0 commit comments