{"id":66,"date":"2013-06-28T12:33:03","date_gmt":"2013-06-28T12:33:03","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=66"},"modified":"2013-07-02T12:07:48","modified_gmt":"2013-07-02T12:07:48","slug":"how-to-set-java-date-to-particular-day","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/how-to-set-java-date-to-particular-day\/","title":{"rendered":"How to set java date to particular day"},"content":{"rendered":"<p>Once a Time I had a Scenario where I should display a Page with List of employees movement from Last Friday to this week Saturday if Saturday is over(you are in Sunday).If you are in any other day other than Saturday(Mon..Fri) then you should choose date of Last before Saturday to Friday.<\/p>\n<p>The above would be made with the following <\/p>\n<p><img decoding=\"async\" src=\"http:\/\/codethataint.com\/blog\/wp-content\/uploads\/2013\/06\/1.png\" alt=\"Image 1\" height=\"259\"\/><br \/>\n<img decoding=\"async\" src=\"http:\/\/codethataint.com\/blog\/wp-content\/uploads\/2013\/06\/2.png\" alt=\"Image 1\" height=\"259\"\/><\/p>\n<p>As you can see in the above diagram I have added two calendar.<\/p>\n<p>In First I should Get Date between  15 to 21 since today date is this 28 and Saturday is not over<br \/>\nIn Second I should Get Date between  22 to 28 since today date is this 30 nd Saturday is over <\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n  java.util.Date dt    = new java.util.Date();\r\n  SimpleDateFormat sdf = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);\r\n  String currentTime   = sdf.format(dt);\r\n  Calendar cal         = Calendar.getInstance();\r\n\r\n  int daysBackToSat = cal.get(Calendar.DAY_OF_WEEK);\r\n  \r\n  \/\/Checks if this weeks friday is Over.in My Case 28 falls on Friday.\r\n  \/\/Returns 6 the below case is True so adds 13 to get before Saturday\r\n  if(daysBackToSat &lt; 7)\r\n   daysBackToSat += 7; \/\/6+7\r\n \r\n  \/\/Subtracting 13 Days for Last Saturday \r\n  \/\/Since this Saturday is not Over\r\n  cal.add(Calendar.DATE, daysBackToSat * -1);\r\n  System.out.println(&quot;Start Date&quot; + sdf.format(cal.getTime()));\r\n\r\n  cal.add(Calendar.DATE, 6);\r\n  System.out.println(&quot;End Date&quot; + sdf.format(cal.getTime()));\r\n<\/pre>\n<p><strong>Output Code<\/strong><br \/>\n2013-06-15<br \/>\n2013-06-21<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Once a Time I had a Scenario where I should display a Page with List of employees movement from Last Friday to this week Saturday if Saturday is over(you are in Sunday).If you are in any other day other than Saturday(Mon..Fri) then you should choose date of Last before Saturday to Friday. The above would&hellip; <a href=\"https:\/\/codethataint.com\/blog\/how-to-set-java-date-to-particular-day\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-66","post","type-post","status-publish","format-standard","hentry","category-date-and-time"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/66","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=66"}],"version-history":[{"count":7,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/66\/revisions"}],"predecessor-version":[{"id":103,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/66\/revisions\/103"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=66"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=66"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=66"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}