You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/05-data-types/10-date/article.md
+24-24Lines changed: 24 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,23 +1,23 @@
1
-
# Date and time
1
+
# Дата и время
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
+
Представляем вам ещё один встроенный объект: [Date](https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Date). В нём хранятся дата и время, а также методы их обработки.
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
+
Например, данный объект можно использовать для хранения времени создания/изменения, для измерения времени или просто для вывода текущей даты.
6
6
7
-
## Creation
7
+
## Создание
8
8
9
-
To create a new`Date`object call `new Date()` with one of the following arguments:
9
+
Для создания нового объекта`Date`нужно вызвать конструктор `new Date()`:
10
10
11
11
`new Date()`
12
-
: Without arguments -- create a `Date`object for the current date and time:
12
+
: При отсутствии аргументов объект `Date`создаётся на текущие дату и время:
13
13
14
14
```js run
15
15
let now = new Date();
16
-
alert( now ); // shows current date/time
16
+
alert( now ); // текущие дата и время
17
17
```
18
18
19
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.
20
+
: В аргумент можно передать количество миллисекунд (одна тысячная секунды), что поместит в созданный объект `Date`, прошедш object with the time equal to number of milliseconds (1/1000 of a second) passed after the Jan 1st of 1970 UTC+0.
21
21
22
22
```js run
23
23
// 0 means 01.01.1970 UTC+0
@@ -29,7 +29,7 @@ To create a new `Date` object call `new Date()` with one of the following argume
29
29
alert( Jan02_1970 );
30
30
```
31
31
32
-
The number of milliseconds that has passed since the beginning of 1970 is called a *timestamp*.
32
+
Количество миллисекунд, прошедшее с начала 1970 года, обозначается термином *отметка времени* (англ. timestamp).
33
33
34
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).
35
35
@@ -74,43 +74,43 @@ To create a new `Date` object call `new Date()` with one of the following argume
74
74
75
75
## Access date components
76
76
77
-
There are many methods to access the year, month and so on from the `Date` object. But they can be easily remembered when categorized.
77
+
Из объекта `Date` можно выделить и более конкретные значения, такие как год или месяц. Для этого используется множество методов, но если их категоризировать, то они легко запоминаются:
78
78
79
79
[getFullYear()](mdn:js/Date/getFullYear)
80
-
: Get the year (4 digits)
80
+
: Возвращаются четыре цифры, соответствующие году.
81
81
82
82
[getMonth()](mdn:js/Date/getMonth)
83
-
: Get the month, **from 0 to 11**.
83
+
: Получаем порядковый номер месяца **от 0 до 11**.
84
84
85
85
[getDate()](mdn:js/Date/getDate)
86
-
: Get the day of month, from 1 to 31, the name of the method does look a little bit strange.
86
+
: Возвращается день месяца, от 1 до 31, что несколько противоречит названию метода.
: Получаем, соответственно, часы, минуты, секунды или миллисекунды.
90
90
91
91
```warn header="Not `getYear()`, but `getFullYear()`"
92
-
Many JavaScript engines implement a non-standard method`getYear()`. This method is deprecated. It returns 2-digit year sometimes. Please never use it. There is `getFullYear()` for the year.
92
+
Во многих интерпретаторах JavaScript предусмотрен нестандартный и устаревший метод`getYear()`, который порой возвращает год в виде двух цифр. Пожалуйста, обходите его стороной. Если нужно значение года, используйте `getFullYear()`.
93
93
```
94
94
95
-
Additionally, we can get a day of week:
95
+
Кроме того, можно получить определённый день недели:
96
96
97
97
[getDay()](mdn:js/Date/getDay)
98
-
: Get the day of week, from `0` (Sunday) to `6` (Saturday). The first day is always Sunday, in some countries that's not so, but can't be changed.
98
+
: Возвращается значение в пределах от `0` (воскресенье) до `6` (суббота). Несмотря на то, что в ряде стран за первый день недели принят понедельник, в JavaScript начало недели приходится на воскресенье.
99
99
100
-
**All the methods above return the components relative to the local time zone.**
100
+
**Все вышеперечисленные методы возвращают значения в соответствии с местной часовой зоной.**
101
101
102
-
There are also their UTC-counterparts, that return day, month, year and so on for the time zone UTC+0: [getUTCFullYear()](mdn:js/Date/getUTCFullYear), [getUTCMonth()](mdn:js/Date/getUTCMonth), [getUTCDay()](mdn:js/Date/getUTCDay). Just insert the `"UTC"` right after `"get"`.
102
+
Однако существуют и их UTC-вариации, возвращающие день, месяц, год для часовой зоны UTC+0: [getUTCFullYear()](mdn:js/Date/getUTCFullYear), [getUTCMonth()](mdn:js/Date/getUTCMonth), [getUTCDay()](mdn:js/Date/getUTCDay). Для их использования требуется перед `"get"` подставить `"UTC"`.
103
103
104
-
If your local time zone is shifted relative to UTC, then the code below shows different hours:
104
+
Если ваша местная часовая зона сдвинута относительно, то следующий код вернёт разные значения:
105
105
106
106
```js run
107
-
// current date
107
+
// текущая дата
108
108
let date = new Date();
109
109
110
-
// the hour in your current time zone
110
+
// час в вашей текущей часовой зоне
111
111
alert( date.getHours() );
112
112
113
-
// the hour in UTC+0 time zone (London time without daylight savings)
113
+
// час в часовой зоне UTC+0 (лондонское время без перехода на летнее время)
114
114
alert( date.getUTCHours() );
115
115
```
116
116
@@ -255,7 +255,7 @@ for (let i = 0; i < 100000; i++) {
255
255
let end =Date.now(); // done
256
256
*/!*
257
257
258
-
alert( `The loop took ${end - start} ms` ); //subtract numbers, not dates
258
+
alert( `The loop took ${end - start} ms` ); //вычитаются числа, а не даты
0 commit comments