{"id":966,"date":"2018-12-17T18:54:14","date_gmt":"2018-12-17T09:54:14","guid":{"rendered":"https:\/\/chat-messenger.com\/?p=966"},"modified":"2019-07-04T01:23:07","modified_gmt":"2019-07-03T16:23:07","slug":"lich-ngay_trong_tuan","status":"publish","type":"post","link":"https:\/\/chat-messenger.com\/vi\/blog\/java\/calendar-day_of_week","title":{"rendered":"Java: T\u00ecm ng\u00e0y hi\u1ec7n t\u1ea1i trong tu\u1ea7n (h\u00f4m nay)"},"content":{"rendered":"<h2 class=\"common_title\"><a name=\"0\">Java <strong>L\u1ea5y ng\u00e0y hi\u1ec7n t\u1ea1i (ng\u00e0y h\u00f4m nay) trong tu\u1ea7n.<\/strong>\u3002 <strong>L\u1ecbch.NG\u00c0Y_TRONG_TU\u1ea6N<\/strong><\/a><\/h2>\n<p>\n<strong>Java<\/strong> \u0110\u00e2y l\u00e0 m\u1ed9t ch\u01b0\u01a1ng tr\u00ecnh m\u1eabu s\u1eed d\u1ee5ng l\u1edbp Calendar \u0111\u1ec3 l\u1ea5y ng\u00e0y hi\u1ec7n t\u1ea1i (ng\u00e0y h\u00f4m nay) trong tu\u1ea7n.<br \/>\n<br \/>\n\u0110\u1ec3 c\u00f3 \u0111\u01b0\u1ee3c n\u00f3, <strong>L\u1ecbch.NG\u00c0Y_TRONG_TU\u1ea6N<\/strong> Ch\u00fang ta s\u1ebd s\u1eed d\u1ee5ng c\u00e1i n\u00e0y.\n<\/p>\n<div class=\"point\">\nCalendar cal = Calendar.getInstance(); <br \/>\nint week = cal.get(Calendar.DAY_OF_WEEK);\n<\/div>\n<p><strong>L\u1ecbch.NG\u00c0Y_TRONG_TU\u1ea6N<\/strong>Gi\u00e1 tr\u1ecb tr\u1ea3 v\u1ec1 l\u00e0 m\u1ed9t s\u1ed1 t\u1eeb 1 \u0111\u1ebfn 7, b\u1eaft \u0111\u1ea7u t\u1eeb 1 cho ng\u00e0y Ch\u1ee7 nh\u1eadt, v\u00ec v\u1eady ch\u01b0\u01a1ng tr\u00ecnh m\u1eabu s\u1eed d\u1ee5ng c\u00e2u l\u1ec7nh switch \u0111\u1ec3 x\u00e1c \u0111\u1ecbnh ng\u00e0y trong tu\u1ea7n.<\/p>\n<h2 class=\"common_title\"><a name=\"1\">Ch\u01b0\u01a1ng tr\u00ecnh m\u1eabu<\/a><\/h2>\n<pre class=\"sample_src\">\/**\r\n * \u73fe\u5728\u306e\u66dc\u65e5\u3092\u8fd4\u3057\u307e\u3059\u3002\r\n * @return\t\u73fe\u5728\u306e\u66dc\u65e5\r\n *\/\r\npublic static String getDayOfTheWeek() { \r\n    Calendar cal = Calendar.getInstance(); \r\n    switch (cal.get(Calendar.DAY_OF_WEEK)) {\r\n        case Calendar.SUNDAY: return \"\u65e5\u66dc\u65e5\";\r\n        case Calendar.MONDAY: return \"\u6708\u66dc\u65e5\";\r\n        case Calendar.TUESDAY: return \"\u706b\u66dc\u65e5\";\r\n        case Calendar.WEDNESDAY: return \"\u6c34\u66dc\u65e5\";\r\n        case Calendar.THURSDAY: return \"\u6728\u66dc\u65e5\";\r\n        case Calendar.FRIDAY: return \"\u91d1\u66dc\u65e5\";\r\n        case Calendar.SATURDAY: return \"\u571f\u66dc\u65e5\";\r\n    }\r\n    throw new IllegalStateException();\r\n}\r\n\/**\r\n * \u73fe\u5728\u306e\u66dc\u65e5\u3092\u8fd4\u3057\u307e\u3059\u3002\r\n * \u203b\u66dc\u65e5\u306f\u7701\u7565\u3057\u307e\u3059\u3002\r\n * @return\t\u73fe\u5728\u306e\u66dc\u65e5\r\n *\/\r\npublic static String getDayOfTheWeekShort() { \r\n    Calendar cal = Calendar.getInstance(); \r\n    switch (cal.get(Calendar.DAY_OF_WEEK)) {\r\n        case Calendar.SUNDAY: return \"\u65e5\";\r\n        case Calendar.MONDAY: return \"\u6708\";\r\n        case Calendar.TUESDAY: return \"\u706b\";\r\n        case Calendar.WEDNESDAY: return \"\u6c34\";\r\n        case Calendar.THURSDAY: return \"\u6728\";\r\n        case Calendar.FRIDAY: return \"\u91d1\";\r\n        case Calendar.SATURDAY: return \"\u571f\";\r\n    }\r\n    throw new IllegalStateException();\r\n}\t\r\n<\/pre>\n<p><script type=\"text\/javascript\" src=\"https:\/\/chat-messenger.com\/js\/common.js?dd12sssas2223\" charset=\"UTF-8\"><\/script><br \/>\n<script type=\"text\/javascript\"> writePR(); <\/script><\/p>\n<h2 class=\"common_title\"><a name=\"2\">K\u1ebft qu\u1ea3 th\u1ef1c thi<\/a><\/h2>\n<p>\u25c6V\u00ed d\u1ee5<\/p>\n<pre class=\"sample_src\">public static void main(String[] args) { \/\/ Hi\u1ec3n th\u1ecb ng\u00e0y trong tu\u1ea7n hi\u1ec7n t\u1ea1i. System.out.println(&quot;H\u00f4m nay l\u00e0 &quot; + getDayOfTheWeek() + &quot;.&quot;); \/\/ Hi\u1ec3n th\u1ecb ng\u00e0y trong tu\u1ea7n hi\u1ec7n t\u1ea1i (d\u1ea1ng vi\u1ebft t\u1eaft). System.out.println(&quot;H\u00f4m nay l\u00e0 &quot; + getDayOfTheWeekShort() + &quot;.&quot;); }\r\n<\/pre>\n<p>\u25c6K\u1ebft qu\u1ea3 \u0111\u1ea7u ra<\/p>\n<pre class=\"console\">H\u00f4m nay l\u00e0 th\u1ee9 T\u01b0. H\u00f4m nay l\u00e0 ng\u00e0y c\u1ee7a N\u01b0\u1edbc.\r\n<\/pre>","protected":false},"excerpt":{"rendered":"<p>java \u73fe\u5728\uff08\u4eca\u65e5\uff09\u306e\u66dc\u65e5\u3092\u53d6\u5f97\u3002 Calendar.DAY_OF_WEEK Java \u3067 Calendar [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[19],"tags":[],"class_list":["post-966","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/posts\/966","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/comments?post=966"}],"version-history":[{"count":7,"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/posts\/966\/revisions"}],"predecessor-version":[{"id":3708,"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/posts\/966\/revisions\/3708"}],"wp:attachment":[{"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/media?parent=966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/categories?post=966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chat-messenger.com\/vi\/wp-json\/wp\/v2\/tags?post=966"}],"curies":[{"name":"trang web","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}