createTime.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Created by chen on 2017/6/27.
  3. */
  4. !function (w) {
  5. function a(w){
  6. this.yaer=new Date().getFullYear();
  7. this.json=[];
  8. this.days=0;
  9. this.nowyear=0;
  10. }
  11. a.prototype={
  12. constructor:a,
  13. init:function(){
  14. this.createJSON();
  15. },
  16. createJSON:function(){
  17. for(var i=0;i<10;i++){
  18. this.nowyear=this.yaer+i;
  19. this.json[i]={
  20. "name":this.nowyear,
  21. "sub":[]
  22. };
  23. for(var j=0;j<12;j++){
  24. this.json[i]['sub'][j]={
  25. "name":(j+1),
  26. "sub":[]
  27. }
  28. this.days=this.getDay(this.nowyear,j+1);
  29. for(var n=0;n<this.days;n++){
  30. this.json[i]['sub'][j]['sub'][n]={
  31. "name":n+1
  32. }
  33. }
  34. }
  35. }
  36. },
  37. getDay:function (year,month) {
  38. if(!(year%4)&&year%100){
  39. if(month=="2") {
  40. return 29;
  41. }else {
  42. return this.otherDay(month);
  43. }
  44. }else {
  45. if(!(year%400)&&$month=="2"){
  46. return 29;
  47. }else {
  48. return this.otherDay(month);
  49. }
  50. }
  51. },
  52. otherDay:function (month) {
  53. switch (month){
  54. case 1: return 31;break;
  55. case 2: return 28;break;
  56. case 3: return 31;break;
  57. case 4: return 30;break;
  58. case 5: return 31;break;
  59. case 6: return 30;break;
  60. case 7: return 31;break;
  61. case 8: return 31;break;
  62. case 9: return 30;break;
  63. case 10: return 31;break;
  64. case 11: return 30;break;
  65. case 12: return 31;break;
  66. }
  67. }
  68. }
  69. var timeJSON=new a();
  70. timeJSON.init();
  71. w.timeJson=timeJSON.json;
  72. }(window)