R
R
Roman Andreevich2019-10-27 21:34:10
JavaScript
Roman Andreevich, 2019-10-27 21:34:10

How to get the day of the week localized for a specific country?

Colleagues, good day, tell me who came across how to get the actual localized day of the week ???

static getDateObject() {

    let object = {};

    let days = {
      0: 'sunday',
      1: 'monday', 
      2: 'tuesday',
      3: 'wednesday', 
      4: 'thursday',
      5: 'friday', 
      6: 'saturday' 
    };

    let locales = `en-AR`;
    let options = {
      timeZone: "America/Argentina/Buenos_Aires",
      hour12: false
    };

    let date = new Date();

    object.full = date.toLocaleString(locales, options);
    object.day = days[date.getDay().toLocaleString(locales, options)];
    object.hour = this.getLocalHour(object.full);

    return object;

  }

everything seems to be normal, it shows the date and time as it should, but the day of the week shows according to my time zone.
PS!!! on nodejs shows my location and in the browser of norms!!!
Thank you in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2019-10-27
@RomanDillerNsk

see Date.toLocaleString()

(new Date()).toLocaleString('es-AR', {
    weekday: 'long'
})
 // "domingo"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question