Advertisement
AnindyaBiswas

datetimemodule

May 16th, 2023 (edited)
706
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. exports.DateTime = function(){
  2.  
  3.     //Day names stored in an array
  4.     let day_name = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
  5.    
  6.     //Date object
  7.     let date_obj = new Date();
  8.  
  9.     //toString not required if you are concating it
  10.     let date = date_obj.getDate().toString();
  11.     let month = (date_obj.getMonth()+1).toString();
  12.     let year = date_obj.getFullYear().toString();
  13.  
  14.     //Day of the week
  15.     let day = day_name[date_obj.getDay()];
  16.  
  17.     //dd-mm-yyyy
  18.     let ddmmyyyy = date + '-' + month + '-' + year;
  19.  
  20.     let hours = date_obj.getHours().toString();
  21.     let minutes = date_obj.getMinutes().toString();
  22.     let secs = date_obj.getSeconds().toString();
  23.  
  24.     //time 24hrs
  25.     let time = hours + ':' + minutes + ':' + secs;
  26.  
  27.     //JSON that will be sent
  28.     let json = {"date":ddmmyyyy, "time":time, "day":day};
  29.  
  30.  
  31.     return json;
  32. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement