JavaScript Localizing day and month in moment.js [duplicate]

This question already has answers here:
Answer:1

For error prone solution for all supported locales, you need to remove year with .replace and check for unnecessary symbols left:

function getCurrDayAndMonth(locale) {
  var today = locale.format('LL');
  return today
    .replace(locale.format('YYYY'), '') // remove year
    .replace(/\s\s+/g, ' ')// remove double spaces, if any
    .trim() // remove spaces from the start and the end
    .replace(/[рг]\./, '') // remove year letter from RU/UK locales
    .replace(/de$/, '') // remove year prefix from PT
    .replace(/b\.$/, '') // remove year prefix from SE
    .trim() // remove spaces from the start and the end
    .replace(/,$/g, ''); // remove comma from the end
}

['af' , 'ar-dz', 'ar-kw', 'ar-ly', 'ar-ma', 'ar-sa', 'ar-tn', 'ar', 'az', 'be', 'bg', 'bn', 'bo', 'br', 'bs', 'ca', 'cs', 'cv', 'cy', 'da', 'de-at', 'de-ch', 'de', 'dv', 'el', 'en-au', 'en-ca', 'en-gb', 'en-ie', 'en-nz', 'eo', 'es-do', 'es', 'et', 'eu', 'fa', 'fi', 'fo', 'fr-ca', 'fr-ch', 'fr', 'fy', 'gd', 'gl', 'gom-latn', 'he', 'hi', 'hr', 'hu', 'hy-am', 'id', 'is', 'it', 'ja', 'jv', 'ka', 'kk', 'km', 'kn', 'ko', 'ky', 'lb', 'lo', 'lt', 'lv', 'me', 'mi', 'mk', 'ml', 'mr', 'ms-my', 'ms', 'my', 'nb', 'ne', 'nl-be', 'nl', 'nn', 'pa-in', 'pl', 'pt-br', 'pt', 'ro', 'ru', 'sd', 'se', 'si', 'sk', 'sl', 'sq', 'sr-cyrl', 'sr', 'ss', 'sv', 'sw', 'ta', 'te', 'tet', 'th', 'tl-ph', 'tlh', 'tr', 'tzl', 'tzm-latn', 'tzm', 'uk', 'ur', 'uz-latn', 'uz', 'vi', 'x-pseudo', 'yo', 'zh-cn', 'zh-hk', 'zh-tw'].forEach(localeName => {
  console.log(
    localeName + ':',
    getCurrDayAndMonth(moment().locale(localeName)));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment-with-locales.min.js"></script>
Answer:2

Do you just want the string representation? If so, it might be easier to just trim the last 5 chars from the end of the output, like so:

var today = moment().locale('tr').format('LL') // "1 Haziran 2017"
today = today.substring(0, today.length - 5); // "1 Haziran"

This'll work for the next 8000 years, so no real need to worry about future years breaking it.

You could even do smarter regex matching, or just remove everything with ", 20XX" from the string. Depends on your uses of it though, this is more of a hacky workaround than a direct solution.

Answer:3

I have been working on a function that loops through a JSON object recursively, and want to use each key it finds as the class value of an element to change the .text value of that element in jQuery. ...

I have been working on a function that loops through a JSON object recursively, and want to use each key it finds as the class value of an element to change the .text value of that element in jQuery. ...

  1. join array values javascript
  2. join array values python
  3. join array values c#
  4. join array values powershell
  5. join array values php
  6. join array values
  7. join array values jquery
  8. join array values java
  9. join array values js
  10. twig join array values
  11. php join array values into string
  12. javascript join array values to string
  13. typescript join array values
  14. postgresql join array values
  15. postgres join array values
  16. bash join array values
  17. join two array values in php
  18. vba join array values
  19. powershell join array values to string
  20. perl join array values

Is there an elegant way (without a for loop) to create a sequential array in Javascript which starts from a certain number and has a certain numbers of items. for example: Start from 2017 and has 4 ...

Is there an elegant way (without a for loop) to create a sequential array in Javascript which starts from a certain number and has a certain numbers of items. for example: Start from 2017 and has 4 ...

I know to find a value exist or not in an array I can use indexOf, but how to do it with an array of object? const x = [{ "id": "roadshows", "name": "Roadshows" }, { "id": "sporting_events", "...

I know to find a value exist or not in an array I can use indexOf, but how to do it with an array of object? const x = [{ "id": "roadshows", "name": "Roadshows" }, { "id": "sporting_events", "...

  1. indexof array object javascript
  2. indexof array object typescript
  3. indexof array object
  4. indexof array object js
  5. indexof array object jquery
  6. indexof(array object) c#
  7. index of array object property
  8. array indexof object property
  9. array indexof object not working
  10. array indexof object key
  11. array indexof object value
  12. array indexof object swift
  13. indexof object array angularjs
  14. indexof object array java
  15. index of object array swift 4
  16. javascript indexof array object property
  17. get index of array object javascript
  18. find index of array object javascript
  19. get index of array object

I'm trying to get the progress of a Firebase upload but the function I'm trying to watch the state with is apparently being called on the wrong object type: Uncaught TypeError: uploadTask.on is not a ...

I'm trying to get the progress of a Firebase upload but the function I'm trying to watch the state with is apparently being called on the wrong object type: Uncaught TypeError: uploadTask.on is not a ...