createTime.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.hours=[];
  9. this.days=0;
  10. this.nowyear=0;
  11. this.hour=0;
  12. }
  13. a.prototype={
  14. constructor:a,
  15. init:function(){
  16. this.createJSON();
  17. this.createHours();
  18. },
  19. createJSON:function(){
  20. for(var i=0;i<10;i++){
  21. this.nowyear=this.yaer+i;
  22. this.json[i]={
  23. "name":this.nowyear,
  24. "sub":[]
  25. };
  26. for(var j=0;j<12;j++){
  27. this.json[i]['sub'][j]={
  28. "name":(j+1),
  29. "sub":[]
  30. }
  31. this.days=this.getDay(this.nowyear,j+1);
  32. for(var n=0;n<this.days;n++){
  33. this.json[i]['sub'][j]['sub'][n]={
  34. "name":n+1
  35. }
  36. }
  37. }
  38. }
  39. },
  40. getDay:function (year,month) {
  41. if(!(year%4)&&year%100){
  42. if(month=="2") {
  43. return 29;
  44. }else {
  45. return this.otherDay(month);
  46. }
  47. }else {
  48. if(!(year%400)&&$month=="2"){
  49. return 29;
  50. }else {
  51. return this.otherDay(month);
  52. }
  53. }
  54. },
  55. createHours:function () {
  56. for(var i=0;i<24;i++){
  57. this.hours[i]={
  58. "name":i+"时",
  59. "sub":[]
  60. };
  61. for(var j=0;j<60;j++){
  62. this.hours[i]['sub'][j]={
  63. "name":j+"分",
  64. "sub":[]
  65. }
  66. }
  67. }
  68. },
  69. otherDay:function (month) {
  70. switch (month){
  71. case 1: return 31;break;
  72. case 2: return 28;break;
  73. case 3: return 31;break;
  74. case 4: return 30;break;
  75. case 5: return 31;break;
  76. case 6: return 30;break;
  77. case 7: return 31;break;
  78. case 8: return 31;break;
  79. case 9: return 30;break;
  80. case 10: return 31;break;
  81. case 11: return 30;break;
  82. case 12: return 31;break;
  83. }
  84. }
  85. }
  86. var timeJSON=new a();
  87. timeJSON.init();
  88. w.timeJson=timeJSON.json;
  89. w.hours=timeJSON.hours;
  90. }(window)