Java gets the Monday date of the week that the date is in by passing in a specified date, in the format of date: 2016-07-30

Source: Internet
Author: User
Tags set time
Java gets the Monday date of the week that the date is in by passing in a specified date, in the format of date: 2016-07-30

private  static  void  convertweekdate (date time)  {                            simpledateformat sdf= new  SimpleDateFormat ("Yyyy-mm-dd"); //Set time format               calendar cal = calendar.getinstance ();              Cal.settime (time);             //Judge whether the date to be calculated is Sunday, if it is minus one day to calculate Saturday, otherwise there will be problems, calculate to the next week to go               int  Dayweek = cal.get (Calendar.day_of_week); Get the current date is the first day of one weeks              if (1  == dayweek)  {               Cal.add (calendar.day_of_ month, -1);            }              System.out.println ("To calculate the date is:" +sdf.format (Cal.gettime ())); //output to calculate date              Cal.setfirstdayofweek (Calendar.monday); Set the first day of the one week, according to China's habit the first day of one weeks is Monday              int  days  = cal.get (Calendar.day_of_week); Get the current date is the day of one weeks              cal.add (calendar.date,  cal.getfirstdayofweek ()-day); According to the rules of the calendar, subtract the difference between the current date and the first day of the one-week    

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.