How to get all dates in a week in java?

Source: Internet
Author: User

Public static void main (String [] args)
{
List <Date> dList = dateToWeek (new Date ());
For (Date d: dList)
{
String dt = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss"). format (d );
System. out. println (dt );
}
}
 
// Call this method. You can input a date to obtain a List of all the days of the week in which the date is located.
@ SuppressWarnings ({"deprecation", "unchecked "})
Public static List <Date> dateToWeek (Date mdate)
{
System. out. println ("mdate:" + mdate );
Int B = mdate. getDay ();
System. out. println ("B:" + B );
Date fdate;
List <Date> list = new ArrayList ();
Long fTime = mdate. getTime ()-B x 24*3600000;
System. out. println ("fTime:" + fTime );
For (int a = 0; a <8; a ++)
{
Fdate = new Date ();
Fdate. setTime (fTime + (a * 24*3600000 ));
List. add (a, fdate );
}

Return list;
}

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.