I am having trouble formatting dates using the Moment.js library on Internet Explorer, it keeps returning

When using the moment.js date library to format a date, I encountered an issue on IE where I would get NaN in the output. This problem did not occur on other browsers such as Chrome and Firefox.

var value = "2015-11";

moment(value).format("YYYY-DD-01 00:00")    
> "0NaN-NaN-01 00:00"   

To resolve this issue, I added the same pattern to the moment constructor as shown below:

> moment(value,"YYYY-DD-01 00:00").format("YYYY-DD-01 00:00")   
"2015-11-01 00:00"  

Would it be considered good practice to include this pattern in the constructor for all moment objects creation in order to ensure compatibility with IE?

Answer №1

Make sure the input format aligns with what you are providing:

let date = "2015-11";
moment(date, "YYYY-MM")

If you need a different format for output, you can use the .format method.

let date = "2015-11";
let m = moment(date, "YYYY-MM")
let formattedDate = m.format("YYYY-MM-DD HH:MM")

Remember that in your code, you specified DD which is for days. It appears you actually meant MM for months.

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

Arrange JSON using JavaScript based on an alternative array order and the remaining items alphabetically

I need help sorting a JSON items with Javascript based on another array, and then alphabetically for the rest of the items. Here is the array of the desired order for sorting the JSON items: var order = [3,9,50,7]; The JSON data has an "ID" key that I w ...

Just built a React App including a blog functionality, but for some reason the blog posts are not showing up. Any suggestions on how to fix this issue

I'm currently working on a project that involves creating a blog page for our react app. Despite my efforts, I am facing difficulty in getting the blog posts to show up. In order to retrieve all the posts from my MYSQL database, I have set up an API ...

At times, the loading image fails to appear on Ajax

Take a look at my code below: function apply_image_effect(){ $.ajax({ url: "image/image.php", global: false, type: "POST", data: ({my_color:encodeURIComponent($('#my_color').val()),my_size:$('#my_size&apos ...

Struggling with making an Ajax and Jquery drop down menu work? Wondering how to use Javascript to retrieve a variable and then utilize it in PHP? Let's troubleshoot

Currently, I am utilizing Ajax/Jquery to present a dropdown menu with data retrieved from my SQL database. The process involves using javascript to obtain a variable that is then utilized in PHP. However, the function doesn't seem to be working as exp ...

Using NextJs to track the position of a scrollbar

Incorporating NextJs for Server Side Rendering has been a game-changer for me. I've also implemented a navbar in my application that needs to adjust styles based on the scroll position. Is there a way to determine if the window has scrolled beyond 100 ...

Maintaining the dropdown in the open position after choosing a dropdown item

The dropdown menu in use is from a bootstrap framework. See the code snippet below: <li id="changethis" class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown>LINK</a> <ul class="dropdown-menu"> <li id ...

How to move an object in Three.js without using translateZ to go forward

In a scenario similar to many others, I am seeking assistance on how to make an object move forward in three.js based on its rotation. The challenge here is that I am unable to utilize object.translateZ due to the interference it causes with the physics si ...

Accordion Tuning - The Pro and Cons

Here is a functional accordion that I've implemented, you can view it here This is the JavaScript code I am using: $(document).ready(function ($) { $('#accordion').find('.accordion-toggle').click(function () { //Expa ...

Toggle the visibility of an HTML element and dynamically change the text of a button

As a beginner in Javascript, I am experimenting with changing button text upon the show/hide of a fieldSet. However, I am encountering some issues with the button text not updating correctly. $(window).on("load", function() { $('.indoor').sl ...

Guidelines for incorporating JS in Framework7

I am developing an application using the framework7. I am facing a challenge where I need to execute some javascript in my page-content, but it is not running as expected. <div class="pages"> <div class="page close-panel" data-page="item"> ...

Utilize Google Maps geocoding functionality to pinpoint a location and then

I've encountered this strange phenomenon, but first let's take a look at the code: HTML <div ng-app='maptesting'> <div ng-controller="MapCtrl"> <div id="map_canvas" ui-map="myMap" style ...

Is the function for identifying the polygon in which a coordinate is located not functioning correctly?

Seeking a function to identify which polygons a coordinate falls within? Check out this function in the GitHub project: https://github.com/mikolalysenko/robust-point-in-polygon. Testing the function with the provided syntax gives the correct result (retur ...

An issue occurred while deploying Docker on Railway services: Build Error

After successfully deploying my Django project on Railway, I decided to add SendGrid mail functionality using the django-sendgrid-v5 package. Everything worked fine in the development environment, including sending emails like user signups. However, when ...

Fastify Schema Failing to Validate Incoming Requests

Currently, our backend setup involves using Node.js and the Fastify framework. We have implemented a schema in satisfy to validate user input. Below is the schema defined in schema.ts: export const profileSchema = { type: 'object', properti ...

Checking the boxes in javascript

Hey there, I'm a JavaScript newbie and struggling to validate my check-boxes. Despite looking at multiple examples, the concept is still not sinking in for me. Could someone please provide guidance on how to properly validate my check-boxes? Additiona ...

Save information on users' Google accounts

Utilizing this resource, I successfully implemented a login feature on my website. The implementation includes functions such as onSignIn, signOut, and auth2.isSignedIn.get() to manage user authentication. Now, I am looking for a way to extract specific d ...

difficulty encountered when passing parameters in functions such as setInterval

Hi everyone, I need some help with my code. Feel free to check it out here Currently, I'm working on implementing multiple circular progress bars that can function dynamically. The goal is to be able to add additional progressCircle_# objects with di ...

What is the best way to send formatted date data to an API using react-datepicker?

I'm encountering an issue while attempting to send a date to my API using react-datepicker in conjunction with Formik to manage nested dates. Despite setting the dateFormat to yyyy/MM/dd, the value I receive is "2020-06-19T04:00:00.000Z". This value g ...

preventing the triggering of the event in the code-behind of the form with a modal popup

Hello there! I am working on a .net website with C# codebehind. I have a LinkButton control that, when clicked, should trigger some backend code. However, I also want to display a modal pop confirmation on the front end when the button is clicked. The moda ...

Reset checkboxes in Material UI data grid

Currently, I am immersed in a React Js project that involves various tabs, each containing a unique data grid table with rows featuring checkboxes. Issue: Whenever I select a row from Table 1 and navigate to Tab 2 before returning to Tab 1, the checkboxes ...