1 var year = 2016; //年份 2 var days = 170; //第几天 3 4 5 function days2month_day(year, days) { 6 "use strict"; 7 var month = "1月"; //默认1月 8 var day = "1日"; 9 var reminder = 0; 10 //闰年 1月31 2月29 3月31 4月30 5月31 6月30 7月31 8月31 9月30 10月31 11月30 12月31 11 if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) { 12 13 if (days - 31 <= 0) { 14 month = "1月"; 15 reminder = days; 16 day = "" + reminder + "日"; 17 } else if (days - 60 <= 0) { 18 month = "2月"; 19 reminder = (days - 31); 20 day = "" + reminder + "日"; 21 22 } else if (days - 91 <= 0) { 23 month = "3月"; 24 reminder = (days - 60); 25 day = "" + reminder + "日"; 26 } else if (days - 121 <= 0) { 27 month = "4月"; 28 reminder = (days - 91); 29 day = "" + reminder + "日"; 30 31 } else if (days - 152 <= 0) { 32 month = "5月"; 33 reminder = (days - 121); 34 day = "" + reminder + "日"; 35 36 } else if (days - 182 <= 0) { 37 month = "6月"; 38 reminder = (days - 152); 39 day = "" + reminder + "日"; 40 41 } else if (days - 213 <= 0) { 42 month = "7月"; 43 reminder = (days - 182); 44 day = "" + reminder + "日"; 45 46 } else if (days - 244 <= 0) { 47 month = "8月"; 48 reminder = (days - 213); 49 day = "" + reminder + "日"; 50 51 } else if (days - 274 <= 0) { 52 month = "9月"; 53 reminder = (days - 244); 54 day = "" + reminder + "日"; 55 56 } else if (days - 305 <= 0) { 57 month = "10月"; 58 reminder = (days - 274); 59 day = "" + reminder + "日"; 60 61 } else if (days - 335 <= 0) { 62 month = "11月"; 63 reminder = (days - 305); 64 day = "" + reminder + "日"; 65 66 } else if (days - 366 <= 0) { 67 month = "12月"; 68 reminder = (days - 335); 69 day = "" + reminder + "日"; 70 } 71 72 73 } 74 else { 75 //平年 2月28天 76 if (days - 31 <= 0) { 77 month = "1月"; 78 reminder = days; 79 day = "" + reminder + "日"; 80 } else if (days - 59 <= 0) { 81 month = "2月"; 82 reminder = (days - 31); 83 day = "" + reminder + "日"; 84 85 } else if (days - 90 <= 0) { 86 month = "3月"; 87 reminder = (days - 59); 88 day = "" + reminder + "日"; 89 } else if (days - 120 <= 0) { 90 month = "4月"; 91 reminder = (days - 90); 92 day = "" + reminder + "日"; 93 94 } else if (days - 151 <= 0) { 95 month = "5月"; 96 reminder = (days - 120); 97 day = "" + reminder + "日"; 98 99 } else if (days - 181 <= 0) { 100 month = "6月"; 101 reminder = (days - 151); 102 day = "" + reminder + "日"; 103 104 } else if (days - 212 <= 0) { 105 month = "7月"; 106 reminder = (days - 181); 107 day = "" + reminder + "日"; 108 109 } else if (days - 243 <= 0) { 110 month = "8月"; 111 reminder = (days - 212); 112 day = "" + reminder + "日"; 113 114 } else if (days - 273 <= 0) { 115 month = "9月"; 116 reminder = (days - 243); 117 day = "" + reminder + "日"; 118 119 } else if (days - 304 <= 0) { 120 month = "10月"; 121 reminder = (days - 273); 122 day = "" + reminder + "日"; 123 124 } else if (days - 334 <= 0) { 125 month = "11月"; 126 reminder =(days - 304); 127 day = "" + reminder + "日"; 128 129 } else if (days - 365 <= 0) { 130 month = "12月"; 131 reminder = (days - 334); 132 day = "" + reminder + "日"; 133 } 134 135 136 } 137 return "" + year + "年" + month + day; 138 } 139 140 var year_month_day = days2month_day(2016, 170); 141 console.log(year_month_day);