{"id":3043,"date":"2016-12-10T09:45:08","date_gmt":"2016-12-10T01:45:08","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=3043"},"modified":"2016-12-10T09:45:08","modified_gmt":"2016-12-10T01:45:08","slug":"%e5%9c%a8python%e4%b8%ad%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96%e6%9f%90%e5%b9%b4%e4%b8%ad%e6%af%8f%e4%b8%aa%e6%9c%88%e7%9a%84%e7%ac%ac%e4%b8%80%e5%a4%a9%e5%92%8c%e6%9c%80%e5%90%8e%e4%b8%80%e5%a4%a9","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/3043.html","title":{"rendered":"\u5728Python\u4e2d\u5982\u4f55\u83b7\u53d6\u67d0\u5e74\u4e2d\u6bcf\u4e2a\u6708\u7684\u7b2c\u4e00\u5929\u548c\u6700\u540e\u4e00\u5929\uff1f"},"content":{"rendered":"<p>=Start=<\/p>\n<h4>\u7f18\u7531\uff1a<\/h4>\n<p>\u7a81\u7136\u60f3\u5230\u7684\u4e00\u4e2a\u95ee\u9898\uff0c\u89c9\u5f97\u6bd4\u8f83\u6709\u8da3\uff0c\u5c31\u5b9e\u9645\u6d4b\u8bd5\u4e86\u4e00\u4e0b\uff0c\u8003\u8651\u5230\u4ee5\u540e\u53ef\u80fd\u4f1a\u6709\u7528\uff0c\u5c31\u8bb0\u5f55\u4e00\u4e0b\u3002<\/p>\n<h4>\u6b63\u6587\uff1a<\/h4>\n<h5>\u641c\u7d22\u5173\u952e\u5b57\uff1a<\/h5>\n<p>python get every first day of month<\/p>\n<h5>\u53c2\u8003\u89e3\u7b54\uff1a<\/h5>\n<h6>\u65b9\u6cd5\u4e00\uff1a<\/h6>\n<pre class=\"lang:default decode:true\">&gt;&gt;&gt; import calendar\n&gt;&gt;&gt; calendar.monthrange(2002,1)\n(1, 31)\n&gt;&gt;&gt; calendar.monthrange(2008,2)\n(4, 29)\n&gt;&gt;&gt; calendar.monthrange(2100,2)\n(0, 28)\n\n&gt;&gt;&gt; calendar.monthrange(2016, 2)[1]<\/pre>\n<h6>\u65b9\u6cd5\u4e8c\uff1a<\/h6>\n<pre class=\"lang:default decode:true\">import datetime\nfor x in xrange(1, 13):\n    dt_start = (datetime.datetime(2016, x, 1)).strftime(\"%Y%m%d\")\n    if 12 == x:\n        dt_end = (datetime.datetime(2016, 12, 31)).strftime(\"%Y%m%d\")\n    else:\n        dt_end = (datetime.datetime(2016, x+1, 1) - datetime.timedelta(days = 1)).strftime(\"%Y%m%d\")\n    print dt_start, dt_end<\/pre>\n<h5>\u53c2\u8003\u94fe\u63a5\uff1a<\/h5>\n<ul>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/42950\/get-last-day-of-the-month-in-python\">http:\/\/stackoverflow.com\/questions\/42950\/get-last-day-of-the-month-in-python<\/a><\/li>\n<li><a href=\"https:\/\/docs.python.org\/2\/library\/calendar.html\">https:\/\/docs.python.org\/2\/library\/calendar.html<\/a><\/li>\n<li><a href=\"https:\/\/docs.python.org\/2\/library\/datetime.html\">https:\/\/docs.python.org\/2\/library\/datetime.html<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/22696662\/python-list-of-first-day-of-month-for-given-period\">http:\/\/stackoverflow.com\/questions\/22696662\/python-list-of-first-day-of-month-for-given-period<\/a><\/li>\n<\/ul>\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u7a81\u7136\u60f3\u5230\u7684\u4e00\u4e2a\u95ee\u9898\uff0c\u89c9\u5f97\u6bd4\u8f83\u6709\u8da3\uff0c\u5c31\u5b9e\u9645\u6d4b\u8bd5\u4e86\u4e00\u4e0b\uff0c\u8003\u8651\u5230\u4ee5\u540e\u53ef\u80fd\u4f1a\u6709\u7528\uff0c\u5c31\u8bb0\u5f55\u4e00\u4e0b\u3002 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,7],"tags":[695,166,8],"class_list":["post-3043","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-programing","tag-calendar","tag-datetime","tag-python"],"views":3805,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/3043","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=3043"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/3043\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=3043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=3043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=3043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}