{"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":"calendar-day_of_week","status":"publish","type":"post","link":"https:\/\/chat-messenger.com\/en\/blog\/java\/calendar-day_of_week","title":{"rendered":"Java Finds the current (today's) day of the week"},"content":{"rendered":"<h2 class=\"common_title\"><a name=\"0\">java <strong>Get the current (today's) day of the week<\/strong>The following is a list of the most common problems with the <strong>Calendar.DAY_OF_WEEK<\/strong><\/a><\/h2>\n<p>\n<strong>Java<\/strong> The following is a sample program to obtain the current (today's) day of the week using the Calendar class in<br \/>\n<br \/>\nTo acquire, <strong>Calendar.DAY_OF_WEEK<\/strong> to be used.\n<\/p>\n<div class=\"point\">\nCalendar cal = Calendar.getInstance(); <br \/>\nint week = cal.get(Calendar.DAY_OF_WEEK);\n<\/div>\n<p><strong>Calendar.DAY_OF_WEEK<\/strong>The return value that can be obtained with the \"return\" statement is a number from 1 to 7, with Sunday starting with 1, so the sample program uses a switch statement to determine the day of the week.<\/p>\n<h2 class=\"common_title\"><a name=\"1\">sample program<\/a><\/h2>\n<pre class=\"sample_src\">\/**\r\n * @return current day of the week.\r\n * @return current day of the week\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 \"Sunday\";\r\n        \r\n        TUESDAY: return \"Tuesday\"; case Calendar.\r\n        WEDNESDAY: return \"Wednesday\"; case Calendar.\r\n        THURSDAY: return \"Thursday\"; case Calendar.\r\n        FRIDAY: return \"Friday\"; case Calendar.\r\n        SATURDAY: return \"Saturday\"; case Calendar.\r\n    }\r\n    throw new IllegalStateException(); }\r\n}\r\n\/**\r\n * Returns the current day of the week.\r\n * * Omit the day of the week.\r\n * @return current day of the week\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 \"day\";\r\n        case Calendar.MONDAY: return \"month\"; case Calendar.TUESDAY: return \"month\";\r\n        TUESDAY: return \"fire\"; case Calendar.\r\n        WEDNESDAY: return \"water\"; case Calendar.\r\n        THURSDAY: return \"Thursday\"; case Calendar.\r\n        FRIDAY: return \"Friday\"; case Calendar.\r\n        SATURDAY: return \"SATURDAY\"; case Calendar.SATURDAY: return \"SATURDAY\"; }\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\">Execution Result<\/a><\/h2>\n<p>\u25c6Example of Execution<\/p>\n<pre class=\"sample_src\">public static void main(String[] args) {\r\n    \/\/ Display today's day of the week.\r\n    System.out.println(\"Today is \" + getDayOfTheWeek() + \")\") ;\r\n    \/\/ Display today's day of the week. Abbreviation.\r\n    System.out.println(\"Today is \" + getDayOfTheWeekShort() + \")) ;\r\n}\r\n<\/pre>\n<p>\u25c6Output result<\/p>\n<pre class=\"console\">Today is \"Wednesday.\r\nToday is \"Wednesday.\r\n<\/pre>","protected":false},"excerpt":{"rendered":"<p>java Get the current (today) day of the week. Calendar.DAY_OF_WEEK Calendar in Java [\u2026]<\/p>","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":""},"categories":[19],"tags":[],"_links":{"self":[{"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/posts\/966"}],"collection":[{"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/comments?post=966"}],"version-history":[{"count":7,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/posts\/966\/revisions"}],"predecessor-version":[{"id":3708,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/posts\/966\/revisions\/3708"}],"wp:attachment":[{"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/media?parent=966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/categories?post=966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/tags?post=966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}