Advertisement
fbinnzhivko

lastMonthlastDay

Sep 23rd, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function lastMonthlastDay([day, month, year]){
  2.     let date = new Date(year,month-1,day);
  3.  
  4.     let oneDay = 1000 * 60 * 60 * 24; // един ден в секунди
  5.     let newDate = new Date(date.setDate(1));  //задаме със едно да последния ден от месеца
  6.  
  7.     //newDate.getTime милисекунди от 12.01.1970 до сега
  8.  
  9.     newDate = new Date(newDate.getTime() - oneDay);
  10.     console.log(newDate.getDate()); //показва датата като разлика 1970 до тарсената дата пресметната във милисекунди
  11. }
  12.  
  13. lastMonthlastDay(['17','3','2002'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement