Java date operation: Find Monday and Sunday

Source: Internet
Author: User

1/**
2* <p>
3* Findsunday Method-mainly used. Find Sunday
4* </p>
5* <p>
6* Created by Xiayh creation time 2014-7-21-5:52:58
7* </p>
8* <blockquote>
9* Ten* <ul>
One * <li> Modified Person Modification Time description
A* </ul>
-* </blockquote>
-     * @return
the     */
-PrivateDate Findsunday (date currentdate) {
-Date CD =NULL;
-intWeekDay = Dateutils.getcurrentdayofweek ();
+Calendar Calendar =NewGregorianCalendar ();
-Calendar.settime (currentdate);
+if(WeekDay >1) {//not Sunday.
A            //Find Sunday
atCalendar.add (Calendar. DATE, (8-weekday));//
-cd = Calendar.gettime ();
-}Else{
-//It 's Sunday .
-cd = currentdate;
-}
inreturncd
-}
to
+/**
-* <p>
the* Findmonday Method-mainly used. Find Monday
** </p>
$* <p>
Panax Notoginseng* Created by Xiayh creation time 2014-7-21-10:15:22
-* </p>
the* <blockquote>
+* A* <ul>
the* <li> Modified person Modification Time description
+ * </ul>
-* </blockquote>
$     * @paramcurrentdate
$     * @return
-     */
-PrivateDate Findmonday (date currentdate) {
theDate CD =NULL;
-intWeekDay = Dateutils.getcurrentdayofweek ();
WuyiCalendar Calendar =NewGregorianCalendar ();
theCalendar.settime (currentdate);
-if(WeekDay >2) {//not Monday.
Wu            //Find Sunday
-Calendar.add (Calendar. date,-(weekDay-2));//
Aboutcd = Calendar.gettime ();
$}Else{
-//It 's Monday .
-cd = currentdate;
-}
AreturnAdy
+}

Java date operation: Find Monday and Sunday

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.