How to fix the javascript Date object

javascript date format
javascript new date from string
javascript date library
javascript date format dd-mmm-yyyy
moment js
javascript date format yyyy-mm-dd
javascript new date() returns invalid date
javascript date now

I have a website with an automatic updating footer, where you can find the date. But the footer gives the complete wrong date. This is the code behind it:

$(function(){
    var now = new Date();
    var mm = now.getMonth() + 1;
    $("#footer").html(`© NekoLuka ${now.getFullYear()}/${mm}/${now.getDay()}`);
}

Today is 2018/10/24, But the footer gives 2018/10/3.

Does anyone know how to solve this?

Look at the documentation on MDN.

You are using getDay:

Returns the day of the week (0-6) for the specified date according to local time.

You should be using getDate:

Returns the day of the month (1-31) for the specified date according to local time.

Date, Date objects contain a Number that represents milliseconds since 1 January 1970 UTC. Description. The ECMAScript epoch and timestamps. A  Sets the hour of a date object, according to universal time. setUTCMilliseconds () Sets the milliseconds of a date object, according to universal time. setUTCMinutes () Set the minutes of a date object, according to universal time. setUTCMonth () Sets the month of a date object, according to universal time.

now.getDay() gets the date of the week, you need now.getDate() to get the current day

Date.prototype.setDate(), The setDate() method sets the day of the Date object relative to the beginning of the currently set month. The following methods provide access to a Date object's time information: getHours(): Returns the hour portion of the time. getMinutes(): Returns the minutes portion of the time. getSeconds

The date is coming wrong because you are using getDay to get current date instead of getDate

replace now.getDay() with now.getDate()

Everything You Need to Know About Date in JavaScript, There's a huge problem with creating dates with date strings. You can The native Date object comes with seven formatting methods. Each of  The Date object is a datatype built into the JavaScript language. Date objects are created with the new Date( ) as shown below. Once a Date object is created, a number of methods allow you to operate on it. Most methods simply allow you to get and set the year, month, day, hour, minute, second, and

The problem was that I used the getDay() instead of the getDate(). When I used the getDate(), the script worked.

JavaScript Date Set Methods, Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java  Creates date based on date string. new Date (year, month, day, hours, minutes, seconds, milliseconds) Creates date based on specified date and time. To demonstrate the different ways to refer to a specific date, we’ll create new Date objects that will represent July 4th, 1776 at 12:30pm GMT in three different ways.

Use now.getDate() instead of now.getDay()

JavaScript setDate() Method, Return Value: A Number, representing the number of milliseconds between the date object and midnight January 1 1970. JavaScript Version: ECMAScript 1  Unfortunately, even though this is commonly seen, this approach is flawed. JavaScript's Date object will always reflect the UTC-based unix epoch, and the local time zone. The symptom is apparent when you call toString on the resulting date object and still see the local time zone, even though you expected it to be in UTC.

JavaScript - The Date Object, JavaScript - The Date Object - The Date object is a datatype built into the JavaScript For compatibility (in order to avoid the Y2K problem), you should always  Before attempting any other repair method, you must first ensure that JavaScript has been enabled on your web browser, to do this, follow the simple instructions below. Internet Explorer. 1. First ensure you’ve logged into your computer with a user profile that has administrative rights. 2. Then click on Start-> Control Panel.

The Beginner's Guide to JavaScript Date and Time, Having learned how to use Date object to generate dates using various methods, let's see how we can format dates. Date Formatting. There is no  Date Methods. When a Date object is created, a number of methods allow you to operate on it.. Date methods allow you to get and set the year, month, day, hour, minute, second, and millisecond of date objects, using either local time or UTC (universal, or GMT) time.

Fixing JavaScript Date – Getting Started – Maggie's Blog, In this conversation, Brendan gave us some great history on the current Date object in JavaScript. It is now common knowledge that in 1995  How to fix this error: Remove circular references like in the example from any objects you want to convert into JSON. Unexpected token ; Related errors: Expected ), missing ) after argument list. The JavaScript interpreter expected something, but it wasn’t there. Typically caused by mismatched parentheses or brackets.

Comments
  • Your first stop should be the documentation, which tells you that getDay returns the day of the week. You're looking for getDate, which returns the day of the month.
  • now.getDay() // returns day of week;, use now.getDate();
  • copyrightlaws.com/copyright-notice-year — Your copyright notice should display the date of first publication, not today's date.
  • Possible duplicate of How to format a JavaScript date