The writing of Pure Java Weekly

Source: Internet
Author: User
Tags date set time
Import java.util.*;


import Com.unigroup2000.Global;


import java.io.*;


import javax.servlet.http.*;


import java.text.*;


/**


* <p>title: </p>


* <p>description: </p>


* <p>copyright:copyright (c) 2004</p>


* <p>company: </p>


* @author not attributable


* @version 1.0


*/





public class Weekcalendar {


public Weekcalendar () throws ioexception{


}


public Calendar calendarsettime (String scurrdate) {


Calendar Ocalendar = Calendar.getinstance ();


Date odate = new Date ();


SimpleDateFormat sdf= New SimpleDateFormat ("Yyyy-mm-dd");


if (!scurrdate.equals ("") &&scurrdate!=null) {


try{


Ocalendar.settime (Sdf.parse (scurrdate));


}catch (Exception ex) {


Ex.printstacktrace (System.err);


System.out.println ("date format conversion Error: =" +scurrdate);


}


}


Else


Ocalendar.settime (odate);


return Ocalendar;


}


public List Calendar (httpservletrequest request, HttpServletResponse response,string scurrdate) {


string[] oneweekday={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};


Calendar Ocal=null;


String loopdate= "", flag= "";


int iweek=0,icurrweek=0;


Date odate = new Date ();


ocal=calendarsettime (scurrdate)//Set time


Iweek=ocal.get (Calendar.day_of_week)-1;


HashMap ohashmap=new HashMap ();;


String dataset[]= null;


List Dayandweek = new ArrayList ();


for (int i=iweek;i>0;i--) {


Ocal.add (calendar.date,-i);


Loopdate=ocal.get (calendar.year) + "-" + (Ocal.get (calendar.month) +1) + "-" +ocal.get (calendar.date);


Ocal=calendarsettime (scurrdate);//Reset Time


DataSet = new String[2];


dataset[0]=loopdate;


dataset[1]=oneweekday[(icurrweek++)];


Dayandweek.add (DataSet);


}


for (int i=0;i<7-iweek;i++) {


Ocal.add (calendar.date,i);


Loopdate=ocal.get (calendar.year) + "-" + (Ocal.get (calendar.month) +1) + "-" +ocal.get (calendar.date);


Ocal=calendarsettime (scurrdate);


DataSet = new String[2];


dataset[0]=loopdate;


dataset[1]=oneweekday[(icurrweek++)];


Dayandweek.add (DataSet);


}


return dayandweek;


}

















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.