Posted By

Pjotor on 04/16/12


Tagged

time calendar date


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

hurcy


Calendar object


 / Published in: JavaScript
 

URL: http://pjotor.com

Returns a nice little calendar object with month name, week day, month, year, date, days in month, day of week and position in month from now or supplied Date.

  1. function getCal(date) {
  2. var today = date || new Date();
  3. var t_s = today.toString().split(" ")
  4. var year = today.getFullYear();
  5. var month = today.getMonth();
  6. var date = today.getDate();
  7.  
  8. var ld = new Date(year, month, 1, 0, 0);
  9. var ld_s;
  10. var c = [];
  11. for (var i = 1; i < 32; i++) {
  12. ld = new Date(year, month, i, 0, 0);
  13. if (ld.getMonth() !== month) {
  14. break;
  15. }
  16.  
  17. var ld_s = ld.toString().split(" ")
  18. c.push({
  19. weekday: ld_s[0],
  20. daynum: ld.getDay(),
  21. date: i,
  22. today: (i === date)
  23. });
  24. }
  25. return {
  26. monthName: t_s[1],
  27. weekday: t_s[0],
  28. month: month,
  29. year: year,
  30. date: date,
  31. days: c,
  32. daynum: today.getDay(),
  33. p:date/i
  34. };
  35. }

Report this snippet  

You need to login to post a comment.