J
J
jeruthadam2019-07-16 16:28:46
JavaScript
jeruthadam, 2019-07-16 16:28:46

Where can I get an array with data for the days of the week for the datepicker?

I want to make my own datepicker. But where does the data come from? Where to get data type

const days = [
  {
    year: 2019,
    month: 'january',
    number: 1,
    day: 'monday'
  }
]

Or something like that? How do you even know that in such a month there are 28 days, in such a 30 or 31? Is it somehow generated from the time API?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Shvets, 2019-07-16
@jeruthadam

How do you even know that in such a month there are 28 days, in such a 30 or 31?

months from 1 to 12
/** число дней */
function daysInMonth (month, year) {
    return new Date(year, month, 0).getDate();
}
/** день недели 1 числа месяца */
function getFirstDayOfMonth (month, year) {
    return new Date(year, month, 1).toLocaleString('ru', { weekday: 'long' });
   // если просто номер
   // return new Date(year, month, 1).getDay();
}

A
Alexander, 2019-07-16
@NeiroNx

Days of the week are standard, days in months too. A reference point is taken and any date is calculated.
Day of the week: remainder of the division by 7 of the total number of days.
28 or 29 - by the remainder of dividing by 4 the difference between the years of high and required.

V
Vladimir, 2019-07-16
@Casufi

You need an array starting from the given date and ending with the picker period
https://developer.mozilla.org/en-US/docs/Web/JavaS... Take
and fill. You can also take moment.js as a dependency if you need support for different locales.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question