Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.DateTime = function(){
- //Day names stored in an array
- let day_name = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
- //Date object
- let date_obj = new Date();
- //toString not required if you are concating it
- let date = date_obj.getDate().toString();
- let month = (date_obj.getMonth()+1).toString();
- let year = date_obj.getFullYear().toString();
- //Day of the week
- let day = day_name[date_obj.getDay()];
- //dd-mm-yyyy
- let ddmmyyyy = date + '-' + month + '-' + year;
- let hours = date_obj.getHours().toString();
- let minutes = date_obj.getMinutes().toString();
- let secs = date_obj.getSeconds().toString();
- //time 24hrs
- let time = hours + ':' + minutes + ':' + secs;
- //JSON that will be sent
- let json = {"date":ddmmyyyy, "time":time, "day":day};
- return json;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement