Javascript There are always some so-called details that will make you dumbfounded.
A time ago, the project team added a need to require all display time in the system where the date format can be customized
what is the date format can be customized, in the usual, we see the time format is generally " YYYY-MM-DD "form, now to support the following six kinds:
YYYY-MM-DD Hh:mm:ss
MM-DD-YYYY Hh:mm:ss
DD-MM-YYYY Hh:mm:ss
YYYY/MM/DD Hh:mm:ss
MM/DD/YYYY Hh:mm:ss
DD/MM/YYYY Hh:mm:ss
The system also deliberately has a page to customize the format of the system, once set to refresh the page system has a module design time format of the display, all become the latest format.
simple support These are simple, there is a comparison of the pit father is a multi-page sign operation, one page to change the format, the other page does not refresh also have to keep the current page format ( SE specifications).
The current scenario is that the foreground is forwarded to the background before the request is made YYYY-MM-DD , then the logic in the background does not change, and the background returns the data to the current page format.
Now, there is a page to pass a time period string to the background query, for example:
04/16/2015 19:57:10~ 04/16/2015 21:57:10
It needs to be dealt with here.
var eventtime = "04/16/2015 19:57:10~ 04/16/2015 21:57:10"; Eventtime.split ("~");//["04/16/201519:57:10", "04/16/2015 21:57:10"]
the array is then traversed, and each element is then split into["04/16/2015","19:57:10"]and then convert the first half to the latest formatYYYY-MM-DD, replacing the value of the first seat, and then stitching it into a legitimate format.eventtimeto the background, by accident, by using an array ofSplice ()method; Suddenly discovered, its powerful function, share to everybody.
Now, let's talk about Most powerful splice () function w3school on its syntax, as follows:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6B/8A/wKiom1Uvy5vzjCrDAAIwpTWDU7c577.jpg "title=" Splice.jpg "alt=" wkiom1uvy5vzjcrdaaiwptwdu7c577.jpg "/> below to give a few simple examples of implementation, adding and deleting the effect.
adding elements
var arrjxj = [1,2,3,4,5,6];undefinedarrjxj.splice (3,0,12,13,14); []arrjxj[1, 2, 3, 4, 5, 6]arrjxj.splice (3,1,15,16,17); [12]arrjxj[1, 2, 3, 15, 16, 17, 13, 14, 4, 5, 6]
you can see that if you want to add an effect to an element, the first argument is the one you want to replace, the second argument is 0; The third parameter replaces the position element;
Delete Element
Arrjxj.splice (3,3); [17]arrjxj[1, 2, 3, 4, 5, 6]arrjxj.splice (3,2); [14]arrjxj[1, 2, 3, 4, 5, 6]
As you can see, if you do not specify a third parameter, you can implement the deletion of the element at a particular location;
modifying elements
Arrjxj[1, 2, 3, 14]arrjxj.splice (3,2,20,21); [13]arrjxj[1, 2, 3, 20, 21, 14]
the number of the second parameter, like the third parameter bit, can be used as a replacement The results.
Of course, the above example actually changed, the array itself, which belongs to the deep copy , so you need to pay attention to it.
This article is from the "Shuizhongyue" blog, make sure to keep this source http://shuizhongyue.blog.51cto.com/7439523/1633661
JavaScript Array Powerful Splice method