Advertisement
sagaida_sv

dateFunctions

Nov 12th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.        
  2.         function DateFunctions(date1, date2)
  3.         {
  4.             this.date1 = new Date(date1);
  5.             this.date2 = new Date(date2);
  6.  
  7.             this.format = function(date = this.date1){
  8.    
  9.                 return `${date.getDate()}.${date.getMonth()+1}.${date.getFullYear()}`
  10.             }
  11.  
  12.              this.different_date_in_timeshtamp = function(d1, d2) {
  13.                 return Math.abs(+d1 - +d2);
  14.             },
  15.             this.timestamp_to_days = function(bigInt) {
  16.               return Math.round(bigInt/(1000*60*60*24));
  17.  
  18.             },
  19.             this.different_date_in_days = function(date1, date2) {
  20.                 ms = this.different_date_in_timeshtamp(date1, date2);
  21.               return this.timestamp_to_days(ms);
  22.             },
  23.             this.getLastWeekDate = function() {
  24.               date = new Date();
  25.               date.setDate(date.getDate() - 7);
  26.               return this.format(date);
  27.             }
  28.         }
  29.  
  30.         let date_functions = new DateFunctions('2019-10-11', '2019-11-08');
  31.         console.log(date_functions.format(new Date()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement