The default locale for momentJS is set to zh-tw and I'm having trouble changing it

Currently, I am incorporating the momentJS library into my Angular application by pulling it from a CDN:

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script>

Although the default locale should be English ('en'), I am experiencing an issue where the default locale in my app is set to 'zh-tw' for some unknown reason. This seems to have been a known issue in the past (refer to this link and this link), but supposedly has been resolved.

Even when attempting to manually set the global locale, it does not take effect as intended:

In my index.html file:

<script>
    moment.locale('en');
</script>

In my Angular controller:

moment.locale('en');

At this point, the only successful method is setting the locale for each individual moment instance:

var moment1 = moment(myDate);
moment1.locale('en');
var moment2 = moment(moment1).add(24, 'h');
moment2.locale('en');

Answer ā„–1

element, I typically find success when using this code snippet while working with Angular:
.run(["moment", function(moment){
    moment.locale("en");
}]);

Answer ā„–2

This question may have been asked last year, but it is important to highlight a solution for anyone encountering the formatting issue with zh-tw.

I encountered this problem today while using the format method. Fortunately, there is now a more permanent fix available within recent updates.

The initial resolution for this issue dates back to around 2013, with an update that addressed it. However, the problem resurfaced in an update prior to version 2.10.3 and has persisted since then. On January 2, 2016, a new update was released which finally resolved the language defaulting to zh-tw, switching it back to en by default upon updating to Moment 2.11.0.

Although the accepted answer may have worked temporarily, I recommend updating to the latest version of Moment as it provides a more comprehensive solution in my opinion.

For details on all the changes in Moment 2.11.0, refer to issue ID #2735 in the Moment 2.11.0 - Changelog.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Continuously improving the form as they evolve

I am interested in creating a form that automatically sends data when users make changes to it. For instance: Imagine a scenario where a moderator is editing an article and changes values in a select field. As soon as the change is made, an ajax request ...

Troubleshooting: Issues with the functionality of Angular UI-Bootstrap Popover

I have a list generated using angular 'ng-repeat', and I am trying to make it so that when an item is clicked, a popover will appear showing some additional information. I've attempted this multiple times but it doesn't seem to be funct ...

perform a JSON request in a RESTful manner

Can you explain the concept of making a RESTful JSON request? In the given scenario, when Backbone attempts to read or save a model to the server, it calls upon the function known as Backbone.sync. This function, by default, utilizes (jQuery/Zepto).ajax t ...

Choose All Box for Dynamic Tables in AngularJS

Hi everyone, I'm currently working on adding a select-all checkbox to the top of my list of checkboxes using a custom directive. I found some guidance on how to do this in a thread that I came across: https://github.com/lorenzofox3/Smart-Table/issues/ ...

Performing an AJAX POST request in Laravel

I'm struggling with getting this ajax call to work, and I can't seem to figure out what's going wrong. View (html) <div class="col-sm-6 col-xs-3 pl0" style="margin-left: -5px;"> <button class="btn btn-primary visible-xs" n ...

Use vanilla JavaScript to send an AJAX request to a Django view

I'm attempting to make a GET AJAX request to a Django view using vanilla JS. Despite passing is_ajax(), I am having trouble properly retrieving the request object. Below is my JavaScript code. Whether with or without JSON.stringify(data), it does not ...

Display a PDF document within a div using jQuery or AngularJS

How can I display a pdf file inside a div using jQuery/AngularJs? For example: $.get('/helper/test.pdf', function(data){ $("#div1").html(data); // want to show the pdf in this div }); Or with AngularJs: $http({ meth ...

What steps can I take to resolve the issue of the Error value not being iterable?

I encountered an issue in my table where I get the error message value is not iterable when there is no value to iterate through. How can I handle this error in my code? Snippet of Code: if (null != data && data) { data = data.map((item) => ...

Tips for containing a range slider within a div element in a flexbox container

I am currently using Javascript to generate a grid of images, and I want to include a range slider at the bottom of one of the images. Here is a simplified version of my code using flex-container: <style> .flex-container { display: flex; fle ...

Attempting to insert a square-shaped div within a larger square-shaped div and enable it to be moved around by dragging

Imagine this scenario: I have a button and a large div. When the button is clicked, the code adds a new div inside the larger one. However, the new div is not draggable because I didn't implement the necessary code. I'm also trying to figure out ...

Determining the precise location of the div element

I am seeking to determine the precise positions of a div based on its class name. In the screenshot provided, my script for finding the div's position is highlighted in yellow, while the div I am targeting is highlighted in red at the bottom. Currentl ...

Accessing store state in axios plugin with Nuxt.js

I've encountered a problem where I have a token stored, but I'm struggling to access it in my axios plugin while using Nuxt.js. In the past with just Vue, it was simple to import the store and access the token. However, I'm having difficulty ...

Is there a method in AngularJS to compel TypeScript to generate functions instead of variables with IIFE during the compilation process with gulp-uglify?

My AngularJS controller looks like this: ArticleController.prototype = Object.create(BaseController.prototype); /* @ngInject */ function ArticleController (CommunicationService){ //Some code unrelated to the issue } I minified it using gulp: retur ...

Issue: Error encountered while trying to use the removeAttribute() function in Selenium and Java: missing closing parenthesis after argument list

WebElement removeReadOnly=driver.findElement(By.xpath("//input[@id='mat-input-0']")); js.executeScript("document.getElementBypath('//input[@id='mat-input-0']').removeAttribute('readonly');",&quo ...

The issue arises when using multiple route files in Route.js, as it hinders the ability to incorporate additional functions within the

After breaking down Route.js into multiple controllers, I'm stuck on why I can't add an extra function to block permissions for viewing the page. // route.js module.exports = function(app, passport) { app.use('/profile&apos ...

Submitting one form generates and sends two POST requests

I have been sending basic data (without any files) from my form using the $http service. These requests consist of JSON and are processed by my express server. Now, I am looking to incorporate image uploads into my form. This requires "multipart/form-da ...

Using a variable in a Joomla module to create a JavaScript object with PHP

I am currently developing a Joomla module that features a progress bar utilizing the ProgressBar.js plugin. Since this module is designed to load multiple objects on a single page, hardcoding the IDs of these objects is not feasible. To address this, I uti ...

How can I make a method in VueJS wait to execute until after rendering?

There is a button that triggers the parse method. parse: function() { this.json.data = getDataFromAPI(); applyColor(); }, applyColor: function() { for (var i=0; i<this.json.data.length; i++) { var doc = document.getElementById(t ...

Tips for creating a responsive image using Material-UI

Iā€™m facing some challenges in making my page responsive. Specifically, I'm having trouble ensuring that an image remains within the grid container in material UI. Is there a method for making images responsive in this context? Even when I try adding ...

JavaScript inheritance through prototypes and the properties of objects

I am currently exploring the concept of prototyped inheritance in JavaScript for a function. This process is well documented in Wikipedia's javascript article. It functions smoothly when dealing with simple JavaScript types: function Person() { t ...