Skip to content

Commit df65762

Browse files
committed
initial commit
1 parent 9132032 commit df65762

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

1-js/05-data-types/10-date/article.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
# Date and time
1+
# Дата и время
22

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). В нём хранятся дата и время, а также методы их обработки.
44

5-
For instance, we can use it to store creation/modification times, to measure time, or just to print out the current date.
5+
Например, данный объект можно использовать для хранения времени создания/изменения, для измерения времени или просто для вывода текущей даты.
66

7-
## Creation
7+
## Создание
88

9-
To create a new `Date` object call `new Date()` with one of the following arguments:
9+
Для создания нового объекта `Date` нужно вызвать конструктор `new Date()`:
1010

1111
`new Date()`
12-
: Without arguments -- create a `Date` object for the current date and time:
12+
: При отсутствии аргументов объект `Date` создаётся на текущие дату и время:
1313

1414
```js run
1515
let now = new Date();
16-
alert( now ); // shows current date/time
16+
alert( now ); // текущие дата и время
1717
```
1818

1919
`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.
2121

2222
```js run
2323
// 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
2929
alert( Jan02_1970 );
3030
```
3131

32-
The number of milliseconds that has passed since the beginning of 1970 is called a *timestamp*.
32+
Количество миллисекунд, прошедшее с начала 1970 года, обозначается термином *отметка времени* (англ. timestamp).
3333

3434
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).
3535

@@ -74,43 +74,43 @@ To create a new `Date` object call `new Date()` with one of the following argume
7474

7575
## Access date components
7676

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` можно выделить и более конкретные значения, такие как год или месяц. Для этого используется множество методов, но если их категоризировать, то они легко запоминаются:
7878

7979
[getFullYear()](mdn:js/Date/getFullYear)
80-
: Get the year (4 digits)
80+
: Возвращаются четыре цифры, соответствующие году.
8181

8282
[getMonth()](mdn:js/Date/getMonth)
83-
: Get the month, **from 0 to 11**.
83+
: Получаем порядковый номер месяца **от 0 до 11**.
8484

8585
[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, что несколько противоречит названию метода.
8787

8888
[getHours()](mdn:js/Date/getHours), [getMinutes()](mdn:js/Date/getMinutes), [getSeconds()](mdn:js/Date/getSeconds), [getMilliseconds()](mdn:js/Date/getMilliseconds)
89-
: Get the corresponding time components.
89+
: Получаем, соответственно, часы, минуты, секунды или миллисекунды.
9090

9191
```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()`.
9393
```
9494
95-
Additionally, we can get a day of week:
95+
Кроме того, можно получить определённый день недели:
9696
9797
[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 начало недели приходится на воскресенье.
9999
100-
**All the methods above return the components relative to the local time zone.**
100+
**Все вышеперечисленные методы возвращают значения в соответствии с местной часовой зоной.**
101101
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"`.
103103
104-
If your local time zone is shifted relative to UTC, then the code below shows different hours:
104+
Если ваша местная часовая зона сдвинута относительно, то следующий код вернёт разные значения:
105105
106106
```js run
107-
// current date
107+
// текущая дата
108108
let date = new Date();
109109
110-
// the hour in your current time zone
110+
// час в вашей текущей часовой зоне
111111
alert( date.getHours() );
112112
113-
// the hour in UTC+0 time zone (London time without daylight savings)
113+
// час в часовой зоне UTC+0 (лондонское время без перехода на летнее время)
114114
alert( date.getUTCHours() );
115115
```
116116

@@ -255,7 +255,7 @@ for (let i = 0; i < 100000; i++) {
255255
let end = Date.now(); // done
256256
*/!*
257257

258-
alert( `The loop took ${end - start} ms` ); // subtract numbers, not dates
258+
alert( `The loop took ${end - start} ms` ); // вычитаются числа, а не даты
259259
```
260260
261261
## Benchmarking

0 commit comments

Comments
 (0)