{"id":2327,"date":"2020-12-11T08:49:51","date_gmt":"2020-12-10T23:49:51","guid":{"rendered":"https:\/\/qol-kk.com\/wp2\/?p=2327"},"modified":"2020-12-11T08:51:31","modified_gmt":"2020-12-10T23:51:31","slug":"post-2327","status":"publish","type":"post","link":"https:\/\/qol-kk.com\/wp2\/blog\/2020\/12\/11\/post-2327\/","title":{"rendered":"\u3010Python\u3011\u4eca\u6708\u306e\u96c6\u8a08\u3092\u3057\u305f\u3044\u6642\u306b\u4f7f\u3046\u6708\u521d\u306e\u53d6\u5f97\u65b9\u6cd5"},"content":{"rendered":"<h2>\u3010Python\u3011\u4eca\u6708\u306e\u96c6\u8a08\u3092\u3057\u305f\u3044\u6642\u306b\u4f7f\u3046\u6708\u521d\u306e\u53d6\u5f97\u65b9\u6cd5<\/h2>\n<p>\u3053\u3053\u3089\u8fba\u306fPHP\u3067\u3082\u7c21\u5358\u306a\u306e\u3067\u7c21\u5358\u306b\u3067\u304d\u308b\u3060\u308d\u3046\u3068\u8abf\u3079\u305f\u3089\u30c4\u30dc\u3055\u3048\u62bc\u3055\u3048\u308c\u3070\u7c21\u5358\u3067\u3057\u305f\u3002<\/p>\n<h3>\u65e5\u4ed8\u51e6\u7406\u306e\u304a\u3055\u3089\u3044<\/h3>\n<p>UNIX\u6642\u9593\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408<\/p>\n<pre class=\"lang:default decode:true\">import time\r\n\r\n\"\"\"\u30a8\u30dd\u30c3\u30af\u304b\u3089\u306e\u79d2\u6570\u3092\u6d6e\u52d5\u5c0f\u6570\u70b9\u6570\u3067\u8fd4\u3059\"\"\"\r\nut = time.time()\r\n\r\n\"\"\"\u73fe\u5728\u306e\u30b9\u30ec\u30c3\u30c9\u306e\u30b7\u30b9\u30c6\u30e0\u304a\u3088\u3073\u30e6\u30fc\u30b6\u30fc\u306e CPU \u6642\u9593\u306e\u5408\u8a08\u5024 (\u5c0f\u6570\u70b9\u4ee5\u4e0b\u3042\u308a\u306e\u79d2\u6570) \u3092\u8fd4\u3059\"\"\"\r\nut = time.thread_time()\r\n\r\n\u201d\u201d\u201dthreadtime\u3092\u30ca\u30ce\u79d2\u3067\u8fd4\u3059\u203bINT\u306b\u306a\u308b\u201d\u201d\u201d\r\nut = time.thread_time_ns()\r\n\r\n\"\"\"\u30a8\u30dd\u30c3\u30af\u304b\u3089\u306e\u79d2\u6570\u3092\u30ca\u30ce\u79d2\u3067\u8fd4\u3059\u203bINT\u306b\u306a\u308b\"\"\"\r\nut = time.time_ns()\r\n\r\n\"\"\"\u30e9\u30a4\u30d6\u30e9\u30ea\u30eb\u30fc\u30c1\u30f3\u3067\u4f7f\u7528\u3055\u308c\u308b\u6642\u9593\u5909\u63db\u30eb\u30fc\u30eb\u3092\u30ea\u30bb\u30c3\u30c8\u3059\u308b\"\"\"\r\nut = time.tzset()<\/pre>\n<p>DateTime\u578b\u51e6\u7406\u306e\u5834\u5408<\/p>\n<pre class=\"lang:default decode:true \">import datetime\r\n\r\n\"\"\"\u73fe\u5728\u306e\u65e5\u4ed8\uff0b\u6642\u523b\u3092\u53d6\u5f97\"\"\"\r\ndt_now = datetime.datetime.now()\r\n\r\n\"\"\"\u4eca\u65e5\u306e\u65e5\u4ed8\u3092\u53d6\u5f97\"\"\"\r\nd_today = datetime.date.today()\r\n\r\n\"\"\"\u73fe\u5728\u306e\u6642\u9593\u3060\u3051\u53d6\u5f97 \u203b\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u7121\u8996\"\"\"\r\nt_now = datetime.datetime.now().time()\r\n\r\n\"\"\"\u73fe\u5728\u306e\u6642\u9593\u3060\u3051\u53d6\u5f97 \u203b\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u6d3b\u7528\"\"\"\r\ndt_now_utc_aware = datetime.datetime.now().timetz()<\/pre>\n<p>\u30a8\u30dd\u30c3\u30af\u79d2\u304b\u5426\u304b\u3067 import \u3059\u308b\u30e2\u30b8\u30e5\u30fc\u30eb\u304c\u5909\u308f\u308b\u70b9\u306b\u6ce8\u610f\u3067\u3059\u3002<\/p>\n<h3>\u4eca\u6708\u6708\u521d\u3092\u53d6\u5f97\u3059\u308b<\/h3>\n<pre class=\"lang:default decode:true\">#python\u3067\u6708\u521d\u3092\u7b97\u51fa\r\ndatetime.date.today().replace(day=1)<\/pre>\n<p>today()\u3067\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u306eday\u30921\u306bReplace\u3059\u308b\u3068\u3002<br \/>\n\u3061\u306a\u307f\u306b\u3001PHP\u306e\u5834\u5408\u306f\u4e0b\u306e\u611f\u3058\u3067\u51fa\u6765\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">#PHP\u3067\u6708\u521d\u3092\u7b97\u51fa\r\n$startDate = new DateTime('first day of this month');\r\n\r\n#\u3053\u3093\u306a\u306e\u3067\u3082OK\r\n$first_date = date(\"Y-m-01\");\r\n<\/pre>\n<h3>\u4eca\u6708\u672b\u306e\u53d6\u5f97\u306f\u3069\u3046\u306a\u308b\u304b<\/h3>\n<p>\u53d6\u5f97\u3057\u305f\u65e5\u306eday\u30921\u306bReplace\u3068\u306a\u308b\u3068\u300130\/31\/28\u306a\u3069\u5909\u52d5\u3059\u308b\u672b\u65e5\u306f\u3069\u3046\u306a\u308b\u304b\u6c17\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">#python\u3067\u6708\u672b\u3092\u7b97\u51fa\r\ndatetime.date.today().replace(day=calendar.monthrange(dt.year, dt.month)[1])<\/pre>\n<p>\u6708\u306e\u6700\u7d42\u65e5 = \u6307\u5b9a\u3057\u305f\u6708\u306e\u65e5\u6570 \u3067\u3059\u3088\u306d\u3002\u305d\u306e\u8003\u3048\u306b\u57fa\u3065\u3044\u3066\u30ab\u30ec\u30f3\u30c0\u30fc\u304b\u3089\u65e5\u6570\u3092\u53d6\u5f97\u3057\u3066Day\u3092\u7f6e\u304d\u63db\u3048\u307e\u3059\u3002<br \/>\n\u3061\u306a\u307f\u306b\u3001PHP\u306e\u5834\u5408\u306f\u4e0b\u306e\u611f\u3058\u3067\u51fa\u6765\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">#PHP\u3067\u6708\u672b\u3092\u7b97\u51fa\r\n$last_date = new DateTime(\"last day of this month\");\r\n\r\n#\u3053\u3093\u306a\u306e\u3067\u3082OK\r\n$last_date = date(\"Y-m-t\");<\/pre>\n<p>\u203bt = \u6307\u5b9a\u3057\u305f\u6708\u306e\u65e5\u6570 \uff1d \u6708\u672b<\/p>\n<h3>\u6708\u521d\u3092\u53d6\u5f97\u3067\u304d\u308b\u3068\u53ef\u80fd\u306a\u4e8b<\/h3>\n<p>\u7121\u99c4\u306a\u30c7\u30fc\u30bf\u3092\u9664\u5916\u3057\u3066\u4eca\u6708\u306e\u96c6\u8a08\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u58f2\u4e0a\u30c7\u30fc\u30bf\u304c\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u30c6\u30fc\u30d6\u30eb\u5185\u306b\u306f\u5148\u6708\u306e\u30c7\u30fc\u30bf\u3082\u53bb\u5e74\u306e\u30c7\u30fc\u30bf\u3082\u5165\u3063\u3066\u3044\u305f\u308a\u3057\u307e\u3059\u3002<\/p>\n<p>\u3044\u304f\u3089pandas\u304c\u512a\u308c\u3066\u3044\u308b\u3068\u306f\u3044\u3048\u3001\u3053\u306e\u3059\u3079\u3066\u306e\u30c7\u30fc\u30bf\u306b\u5bfe\u3057\u3066\u6708\u6b21\u96c6\u8a08\u3092\u3057\u3066\u6700\u65b0\u6708\u3092\u8868\u793a\u3059\u308b\u306a\u3093\u3066\u306e\u306f\u30b5\u30fc\u30d0\u30fcSpec\u306e\u7121\u99c4\u9063\u3044\u3002\u4eca\u6708\u3060\u3051\u5fc5\u8981\u306a\u306e\u3067\u3042\u308c\u3070\u4eca\u6708\u306e\u30c7\u30fc\u30bf\u3092\u5148\u306b\u62bd\u51fa\u3057\u3066\u3057\u307e\u3048\u3070\u3044\u3044\u306e\u3067\u3059\u304c\u3001\u305d\u306e\u969b\u306b\u6708\u521d\u3068\u4eca\u65e5\u3068\u3044\u3046\u30d5\u30a3\u30eb\u30bf\u3092\u4f7f\u3048\u3070OK\u3068\u8a00\u3046\u4e8b\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">from datetime\r\n\r\nd= datetime.date.today()\r\nfd = get_first_date(d)\r\n\r\nSalesData.objects.filter(observation_date__range=[fd, d])<\/pre>\n<h3>\u307e\u3068\u3081<\/h3>\n<p>\u65e5\u4ed8\u51e6\u7406\u3063\u3066\u4f7f\u3046\u6a5f\u4f1a\u591a\u3044\u306e\u3067\u7c21\u5358\u306b\u3067\u304d\u308b\u3068\u5b09\u3057\u3044\u306e\u3067\u3059\u304c\u3001python\u3067\u306f\u5c11\u3057\u3081\u3093\u3069\u304f\u3055\u3044\u624b\u7d9a\u304d\u3092\u3059\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>Python\u3082\u30c4\u30dc\u3092\u62bc\u3055\u3048\u308c\u3070\u7c21\u5358\u306a\u306e\u3067\u3059\u304c\u3001\u3053\u3046\u3044\u3046\u6240\u306fPHP\u4fbf\u5229\u3060\u3063\u305f\u306a\u3041\u3068\u5b9f\u611f\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3010Python\u3011\u4eca\u6708\u306e\u96c6\u8a08\u3092\u3057\u305f\u3044\u6642\u306b\u4f7f\u3046\u6708\u521d\u306e\u53d6\u5f97\u65b9\u6cd5 \u3053\u3053\u3089\u8fba\u306fPHP\u3067\u3082\u7c21\u5358\u306a\u306e\u3067\u7c21\u5358\u306b\u3067\u304d\u308b\u3060\u308d\u3046\u3068\u8abf\u3079\u305f\u3089\u30c4\u30dc\u3055\u3048\u62bc\u3055\u3048\u308c\u3070\u7c21\u5358\u3067\u3057\u305f\u3002 \u65e5\u4ed8\u51e6\u7406\u306e\u304a\u3055\u3089\u3044 UNIX\u6642\u9593\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408 import time  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2173,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"vkexunit_cta_each_option":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[38],"tags":[868,147,867,853,865,53,864,866],"class_list":["post-2327","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-memorandum","tag-now","tag-python","tag-today","tag-unix","tag-865","tag-53","tag-864","tag-866"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/qol-kk.com\/wp2\/wp-content\/uploads\/2020\/11\/python.png","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts\/2327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/comments?post=2327"}],"version-history":[{"count":0,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts\/2327\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/media\/2173"}],"wp:attachment":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/media?parent=2327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/categories?post=2327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/tags?post=2327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}