I have always been very familiar with JavaScript, because I will only learn it when it is used in actual projects.
For details about the propertype attribute in JS, refer to W3C. The prototype attribute allows you to add attributes and methods to an object. This is a magical saying. I have also referred to the design mechanism of the js inheritance idea, and it seems that I understand it.
So after a little practice, I found that it was really convenient:
Date. Prototype. toyymmdd = function () {var month = This. getmonth () <10? ("0" + (this. getmonth () + 1) :( this. getmonth () + 1); var day = This. getdate () <10? ("0" + this. getdate (): This. getdate (); return this. getfullyear () + "-" + month + "-" + day ;};
Then use the following code:
VaR now = new date (); var nowstr = now. toyymmdd ();
In this way, you can customize the date format. In fact, write another function similar to toyymmdd (date). Using date as an input parameter for formatting can also achieve the same effect. The simplicity depends on the actual situation.