the ones on the Internet are so rude that they don"t consider asking for advice from the boss of the year and month
the ones on the Internet are so rude that they don"t consider asking for advice from the boss of the year and month
this thing depends on what you think.
you want one year, two months and three days . Still want 14 months of the year 4 days * *.
there is no standard algorithm for this thing. If you have the logic in your mind, write it down bit by bit.
you can send it out and ask others to optimize it for you, shake the machine and so on. You can also look at the input and output.
my idea is year-year
, and then see whether the time is big or small. If it is small, minus-1, and if it is big, it will not move.
`20180901` `20170902` `0`
`20180902` `20170901` `1`
month-month
, see whether the time is big or small, and this depends on the time before processing
`20180901` `20171002` `010`
`20180801` `20171001` `010`
`20180901` `20171001` `011`
`20181001` `20171001` `10`
`20180902` `20170901` `10`
the number of days is the same, of course.
convert two dates to timestamps, and then subtract them.
stumbled upon a post and solved the problem code as follows
/**
* @desc
* ->->
*
* @date 2015-09-22
* @author WadeYu
*/
var getDiffYmdBetweenDate = function(sDate1,sDate2){
var fixDate = function(sDate){
var aD = sDate.split('-');
for(var i = 0; i < aD.length; iPP){
aD[i] = fixZero(parseInt(aD[i]));
}
return aD.join('-');
};
var fixZero = function(n){
return n < 10 ? '0'+n : n;
};
var fixInt = function(a){
for(var i = 0; i < a.length; iPP){
a[i] = parseInt(a[i]);
}
return a;
};
var getMonthDays = function(y,m){
var aMonthDays = [0,31,28,31,30,31,30,31,31,30,31,30,31];
if((y%400 == 0) || (y%4==0 && y%100!=0)){
aMonthDays[2] = 29;
}
return aMonthDays[m];
};
var checkDate = function(sDate){
};
var y = 0;
var m = 0;
var d = 0;
var sTmp;
var aTmp;
sDate1 = fixDate(sDate1);
sDate2 = fixDate(sDate2);
if(sDate1 > sDate2){
sTmp = sDate2;
sDate2 = sDate1;
sDate1 = sTmp;
}
var aDate1 = sDate1.split('-');
aDate1 = fixInt(aDate1);
var aDate2 = sDate2.split('-');
aDate2 = fixInt(aDate2);
//
/*aTmp = [aDate1[0]+1,fixZero(aDate1[1]),fixZero(aDate1[2])];
while(aTmp.join('-') <= sDate2){
yPP;
aTmp[0]PP;
}*/
y = aDate2[0] - aDate1[0];
if( sDate2.replace(aDate2[0],'') < sDate1.replace(aDate1[0],'')){
y = y - 1;
}
//
aTmp = [aDate1[0]+y,aDate1[1],fixZero(aDate1[2])];
while(true){
if(aTmp[1] == 12){
aTmp[0]PP;
aTmp[1] = 1;
}else{
aTmp[1]PP;
}
if(([aTmp[0],fixZero(aTmp[1]),aTmp[2]]).join('-') <= sDate2){
mPP;
} else {
break;
}
}
//
aTmp = [aDate1[0]+y,aDate1[1]+m,aDate1[2]];
if(aTmp[1] > 12){
aTmp[0]PP;
aTmp[1] -= 12;
}
while(true){
if(aTmp[2] == getMonthDays(aTmp[0],aTmp[1])){
aTmp[1]PP;
aTmp[2] = 1;
} else {
aTmp[2]PP;
}
sTmp = ([aTmp[0],fixZero(aTmp[1]),fixZero(aTmp[2])]).join('-');
if(sTmp <= sDate2){
dPP;
} else {
break;
}
}
return {y:y,m:m,d:d};
};
var aTest = [
['1984-9-17','2015-8-15'],
['1984-9-17','1985-9-18'],
['1984-9-17','1984-10-17'],
['1984-9-17','1984-10-10'],
];
for(var i = 0; i < aTest.length; iPP){
console.log(aTest[i][0]+':'+aTest[i][1]);
console.log(getDiffYmdBetweenDate(aTest[i][0],aTest[i][1]));
}
Code reference: http://www.itkeyword.com/doc/.
Amway time tool
momentjs feels pretty easy to use.
Previous: How to restore hexadecimal string to hexadecimal code in java
Next: When python openpyxl manipulates the table, the cell border disappears after saving the file.
sincerely ask for advice: < hr > I want to use node as the background to build a video streaming server. The front end is similar to Youku VOD. It can record the playback node function, and load the progress bar at any point (starting from the c...
suppose there are only a.js and b.js (only two js and nothing else) b.js export A variable is used for a.js can you directly use import and export without using packaging and compilation tools such as webpack or babel can it be achieved with the h...
you need to build a http service with nodejs, but the service has scheduled tasks to handle. it seems impossible to use native http server. Is there any way to do it? Or other modules? ...
Please recommend the library reported by error monitoring at the front end, or post relevant codes the discovery written by myself is not comprehensive, unable to listen for resource errors, but can only listen for run-time errors. I don t know if th...
this visual studio code has inexplicably linked more than 5,000 files after I built a project inexplicably, which may be related to GitHub. excuse me, how did this happen? how can I fix it? every time I open it, I feel so unhappy Thank you! ...
suddenly became interested in mongodb, installed and started with brew according to the rookie tutorial, but showed "waiting for connections on port 27017 " for a long time, then as a front-end younger brother who still has a narrow range of knowle...
the backend returns the image address, and after stitching the string, it is displayed on the page The actual address displayed by the src of img is http: localhost:port + picture address which god knows how to solve this problem img src img src...
packages previously installed globally through npm fail when nvm changes versions cnpm no damn commands can be used, how to solve it? ...
is in window. How to deal with it? Be in a hurry ...
as shown in the picture, red, is there something wrong ...
whether all web access must be port 80, because port 80 will be reviewed if I deploy a website on the CVM that is port 3000, is not allowed by policy. Both the server and domain name are registered ....
node returns the code of the file: http: response, , , No response looking for support from an experienced dalao has been bothering me for a long time ...
1. Write some mini applications with node recently. Using mongoose. There is a small problem. Do not understand (may not understand the English document or do not understand). for example: video.find({},(err, videos) => { videos.forEac...
actions such as filling out forms, clicking buttons, etc. ...
the unfinished code on the day of submission (the function has not been written yet). How do you usually write commit for submission? Still don t submit it if you haven t finished it . is there a general team specification? ...
an error was prompted after using server-side rendering mobx Please also explain ...
A vue actual combat project imitating ele.me on Mu course net, which has set up route, uses json file mock data locally, json file is placed in static folder, and wants to be extracted with axios. Just look at the seller section of json. The json conten...
let status = true; while (status) { } console.log ( "not executed here "); ...
there is a problem. Now there is only online packaged vue code left in the project, and then the requirements have edges, but there is no source code. How can I find the source code now? If you can t get it back, is there any way to achieve the increase...
something like this: var aaa = 0; http.get ( http: abc.com api " , function (res) { var json = ; res.on( data , function (d) { json += d; }); res.on( end ,function(){ json = JSON.parse(json); aaa = json; }); }). On ( e...