Guest User

Untitled

a guest
Feb 25th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. function format(val, figure) {
  2. return val < 10 * (figure - 1) ? `0${val}` : `${val}`;
  3. }
  4.  
  5. function dateformat(dateObject) {
  6. const date = dateObject || new Date();
  7.  
  8. const year = format(date.getFullYear(), 4);
  9. const month = format(date.getMonth() + 1, 2);
  10. const day = format(date.getDate(), 2);
  11. const hour = format(date.getHours(), 2);
  12. const minute = format(date.getMinutes(), 2);
  13. const second = format(date.getSeconds(), 2);
  14.  
  15. return {
  16. year,
  17. month,
  18. day,
  19. hour,
  20. minute,
  21. second
  22. };
  23. }
  24.  
  25. module.exports = dateformat;
Add Comment
Please, Sign In to add comment