How to disable only sunday in the following code?
We cannot find any solution to disable sunday for a month
MainActivity.java:
CalendarView calendarView = (CalendarView) findViewById(R.id.calendarView);
Calendar calendar = Calendar.getInstance();
calendarView.setMinDate(calendar.getTimeInMillis());
calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener()
{
#Override
public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
Toast.makeText(getApplicationContext(), "" + dayOfMonth, 0).show();// TODO Auto-generated method stub`enter code here`
}
});
I have used this code in a project. See if it produces desirable result -
//Global Variables
private Calendar lastSelectedCalendar = null;
private CalendarView calendarView;
//
calendarView = (CalendarView) findViewById(R.id.calendarView);
lastSelectedCalendar = Calendar.getInstance();
calendarView.setMinDate(lastSelectedCalendar.getTimeInMillis() - 1000);
calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
#Override
public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
Calendar checkCalendar = Calendar.getInstance();
checkCalendar.set(year, month, dayOfMonth);
if(checkCalendar.equals(lastSelectedCalendar))
return;
if(checkCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
calendarView.setDate(lastSelectedCalendar.getTimeInMillis());
else
lastSelectedCalendar = checkCalendar;
}
});
Calendar sunday;
List<Calendar> weekends = new ArrayList<>();
int weeks = 5;
for (int i = 0; i < (weeks * 7) ; i = i + 7) {
sunday = Calendar.getInstance();
sunday.add(Calendar.DAY_OF_YEAR, (Calendar.SUNDAY - sunday.get(Calendar.DAY_OF_WEEK) + 7 + i));
// saturday = Calendar.getInstance();
// saturday.add(Calendar.DAY_OF_YEAR, (Calendar.SATURDAY - saturday.get(Calendar.DAY_OF_WEEK) + i));
// weekends.add(saturday);
weekends.add(sunday);
}
Calendar[] disabledDays = weekends.toArray(new Calendar[weekends.size()]);
dpd.setDisabledDays(disabledDays);
This code disables the next 5 Sundays, if you wish to do it for a longer period, just need to modify week. If you wish to disable Saturdays too, just uncomment those lines.
If you want to do it for previous 5 Sundays then, just modify the for loop to:
for (int i = 0; i < (weeks * 7); i = i + 7) {
for(int j =0; j > (weeks*7) ; j = j - 7);
sunday = Calendar.getInstance();
sunday.add(Calendar.DAY_OF_YEAR, (Calendar.SUNDAY - sunday.get(Calendar.DAY_OF_WEEK) + 7 + i));
// saturday = Calendar.getInstance();
// saturday.add(Calendar.DAY_OF_YEAR, (Calendar.SATURDAY - saturday.get(Calendar.DAY_OF_WEEK) + i));
// weekends.add(saturday);
weekends.add(sunday);
}
Related
How can I set date in a DatePicker from a string (eg: 02/10/19):
Following is the code:
iqp_editDate.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new DatePickerDialog(ActivityClass.this, (DatePickerDialog.OnDateSetListener) date1, y, m, d).show();
}
});
DatePickerDialog.OnDateSetListener date1 = new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
y = year;
m = month;
d = dayOfMonth;
dateMonth = month + 1;
dateYear = year;
}
};
Update: misunderstood the question:
Calendar cal = Calendar.getInstance()
cal.set(Calendar.HOUR_OF_DAY,18);
cal.set(Calendar.MINUTE,0);
cal.set(Calendar.DATE,2);
cal.set(Calendar.MONTH,9); //Month -1
//Or to set it from a String:
String string = "02/10/19";
DateFormat format = new SimpleDateFormat("dd/MM/yy", Locale.getDefault());
Date date = format.parse(string);
cal.setTimeInMillis(date.getTime());
new DatePickerDialog(getContext(),date1, cal
.get(Calendar.YEAR), cal .get(Calendar.MONTH),
cal .get(Calendar.DAY_OF_MONTH)).show();
A string is a character array. Meaning that you could just make a loop and set the different day, month and year values to different parts of the string.
String date = "02/19/19";
String year = "";
for(int i = 0; i < date.length; i++)
{
month += date.charAt(i);
...
}
Then you'd tell it when to switch from adding to month to day to year when it encounters '/'
if(date.charAt(i) == '/')
{
...
}
at the end of it all if you need to make it into an int then do
int month = Integer.parseInt("month");
sorry I've gotta be going somewhere so I couldn't just write the code out for ya but I'm sure you can figure it out from what I gave ya.
Following code works fine for me:
new DatePickerDialog(Activityclass.this, date1, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)).show();
DatePickerDialog.OnDateSetListener date1 = new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
view.setMinDate(1559327400);
y = year;
m = month;
d = dayOfMonth;
dateMonth = month + 1;
dateYear = year;
iqp_editDate.setText(dayOfMonth + "/" + (month + 1) + "/" + year);
try {
epoch = new java.text.SimpleDateFormat("MM/dd/yyyy").parse(m + "/" + dayOfMonth + "/" + year).getTime() / 1000;
} catch (ParseException e) {
e.printStackTrace();
}
}
};
First off, I'm using the library https://github.com/alamkanak/Android-Week-View
I have an API returning data for one week at a time.
For example GET /stuff/{current_week_number}
Then a scroll listener set up that checks if the week has changed, and will then load
GET /stuff/{new_week_number}
The problem is that all events will be in the current week position as duplicates. I know the library wants events on a per month basis, is it the problem?
Been debugging this for a day now, help would be greatly appreciated.
Function for creating the event:
private WeekViewEvent createNew(JSONObject json, int week) {
String eventTitle = "";
String colorString = "#999";
String startTimeString = "";
String endTimeString = "";
int dayOfWeek = 0;
try {
eventTitle = json.getString("text").replaceAll("\n", " ");
colorString = json.getString("color");
startTimeString = json.getString("startTime");
endTimeString = json.getString("endTime");
dayOfWeek = json.getInt("day");
} catch (JSONException e) {
e.printStackTrace();
}
Calendar startTime = Calendar.getInstance();
startTime.set(Calendar.HOUR_OF_DAY, hoursFromString(startTimeString));
startTime.set(Calendar.MINUTE, minutesFromString(startTimeString));
startTime.set(Calendar.WEEK_OF_YEAR, week);
startTime.set(Calendar.DAY_OF_WEEK, dayOfWeek);
Calendar endTime = (Calendar) startTime.clone();
endTime.set(Calendar.HOUR_OF_DAY, hoursFromString(endTimeString));
endTime.set(Calendar.MINUTE, minutesFromString(endTimeString));
WeekViewEvent event = new WeekViewEvent(mGlobalCounter, eventTitle, startTimeString + " - " + endTimeString, startTime, endTime);
event.setColor(Color.parseColor(colorString));
if (event.getColor() == Color.WHITE) {
event.setColor(R.color.event_color_01);
}
return event;
}
Month change listener + helper method (from example)
private boolean eventMatches(WeekViewEvent event, int year, int month) {
return (event.getStartTime().get(Calendar.YEAR) == year && event.getStartTime().get(Calendar.MONTH) == month - 1) || (event.getEndTime().get(Calendar.YEAR) == year && event.getEndTime().get(Calendar.MONTH) == month - 1);
}
MonthLoader.MonthChangeListener mMonthChangeListener = new MonthLoader.MonthChangeListener() {
#Override
public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
// Populate the week view with some events.
List<WeekViewEvent> events = new ArrayList<>(); //getEvents(newYear, newMonth);
for (WeekViewEvent event : mNewEvents) {
if (eventMatches(event, newYear, newMonth)) {
events.add(event);
}
}
mFetchedWeeks.add(Integer.valueOf(mWeek));
return events;
}
};
And here's the JSON-response from the API
https://gist.github.com/jonathanort/668de267966e3b673fffe23dfbdfb90b
Also, my modified version of WeekView.java
https://gist.github.com/jonathanort/472d86355dcdbc338f13373a838f548a
The solution was to add the line
startTime.get(Calendar.DAY_OF_WEEK);
before
startTime.set(Calendar.DAY_OF_WEEK, dayOfWeek);
Apparently it will not set the day otherwise
UPDATE
I am creating a pregnancy due date countdown, so I use android.widget.DatePicker as a tool to set the due date.
For example:
the set due date is Jan. 9 2015
the date now is Nov. 9 2014
so the left months, days and weeks is 2 months, 62 days and 8weeks
So far i can only display the set due date.
Question:
How to get the exact months weeks and days left when the user set the due date.
UPDATE CODE
Here's the code:
private TextView txtResultDueDate ;
private DatePicker datePicker;
private Calendar calendar;
private int year;
private int month;
private int day;
static final int DATE_DIALOG_ID = 999;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
txtResultDueDate = (TextView) findViewById(R.id.txtDue);
btnChangeDate = (Button)findViewById(R.id.button1);
calendar = Calendar.getInstance();
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH);
day = calendar.get(Calendar.DAY_OF_MONTH);
showDate(year, month+1, day);
#SuppressWarnings("deprecation")
public void setDate(View view) {
showDialog(999);
Toast.makeText(getApplicationContext(), "ca", Toast.LENGTH_SHORT)
.show();
}
#Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
if (id == 999) {
return new DatePickerDialog(this, myDateListener, year, month, day);
}
return null;
}
private DatePickerDialog.OnDateSetListener myDateListener
= new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker arg0, int year, int month, int day) {
Chronology chrono = GregorianChronology.getInstance();
DateTime end = new DateTime(arg0.getYear(), arg0.getMonth(), arg0.getDayOfMonth(), 0, 0, chrono);
DateTime current = new DateTime();
Interval interval = new Interval(current.toInstant(), end.toInstant());
Period duePeriod = interval.toPeriod();
showDate(duePeriod.getYears(), duePeriod.getMonths(), duePeriod.getDays());
}
};
private void showDate(int year, int month, int day) {
txtResultDueDate.setText(new StringBuilder().append(day).append("/")
.append(month).append("/").append(year));
}
This is the error that I encounter when I set the due date using DatePicker:
FATAL EXCEPTION: main
java.lang.IllegalArgumentException: The end instant must be greater orequal to the start
at org.joda.time.base.Abstraction.checkInterval(AbstractInterval.java.63)
at org.joda.time.base.BaseInterval(BaseInterval.java:94)
at org.joda.time.Interval.(Interval.java.122)
at com.date.androin.Profile$1.onDataset(Profile.java:168)
at android.app.DatePickerDialog.tryNotifyDataSet(DatePickerDialog.java.148)
at android.app.DatePickerDialog.onClick(DatePickerDialog.java.116)
at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStrat.main(Native Method)
There is a library Joda Time. It is better the Date API provided by Java
Joda Time has a concept of time Interval:
Interval interval = new Interval(oldTime, new Instant());
Yes, you can use joda lib with android DatePicker
Chronology chrono = GregorianChronology.getInstance();
// end datetime
DateTime end = new DateTime(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth(), 0, 0 ,chrono);
// current datetime
DateTime current = new DateTime();
Then instantiate Interval with start and end datetime
Interval interval = new Interval(current.toInstant(), end.toInstant());
then use the Interval api to get the Period from which you can extract the difference of months/days/weeks
Period duePeriod = interval.toPeriod();
// get difference in months
duePeriod.getMonths();
// get difference in weeks
duePeriod.getWeeks();
PLease refer the below Javadoc of Period for complete list of API
http://joda-time.sourceforge.net/apidocs/org/joda/time/Period.html
For Android, in your case add the above code into your DatePicker onDateSet listener. finally the listener method would like this,
#Override
public void onDateSet(DatePicker arg0, int year, int month, int day) {
// TODO Auto-generated method stub
Chronology chrono = GregorianChronology.getInstance();
// end datetime
DateTime end = new DateTime(arg0.getYear(), arg0.getMonth(), arg0.getDayOfMonth(), 0, 0, chrono);
// current datetime
DateTime current = new DateTime();
Interval interval = new Interval(current.toInstant(), end.toInstant());
Period duePeriod = interval.toPeriod();
showDate(duePeriod.getYears(), duePeriod.getMonths(), duePeriod.getDays());
}
//somewhere in your code, init part
Calendar then = setDate(9, 0, 2015);//9 january 2015
Calendar c = Calendar.getInstance();
Calendar now = setDate(c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.MONTH), c.get(Calendar.YEAR));
String leftDays = getLeftDays(then, now);//your result
//method setting days months years - we ignore hours and minutes
private String getLeftDays(Calendar then, Calendar now) {
long leftMilis = then.getTimeInMillis() - now.getTimeInMillis();
int seconds = (int) (leftMilis / 1000);
Log.d(TAG, "seconds:" + seconds);
int minutes = seconds / 60;
Log.d(TAG, "minutes:" + minutes);
int hours = minutes / 60;
Log.d(TAG, "hours:" + hours);
int days = hours / 24;
Log.d(TAG, "days:" + days);
int weeks = days / 7;
Log.d(TAG, "weeks:" + weeks);
//months.. another way calculating data due not equal amount of days per month
Calendar temp = ((Calendar) then.clone());
temp.add(Calendar.MONTH, -now.get(Calendar.MONTH));
int months = temp.get(Calendar.MONTH);
Log.d(TAG, "months:" + months);
StringBuilder sb = new StringBuilder();
String format = "%d months, %d days, %d weeks";
String formatStr = String.format(format, months, days, weeks);
String result = sb.append(formatStr).toString();
Log.d(TAG, sb.toString());
return result;
}
private Calendar setDate(int day, int month, int year) {
Calendar c = Calendar.getInstance();
c.set(Calendar.DAY_OF_MONTH, day);
c.set(Calendar.MONTH, month);
c.set(Calendar.YEAR, year);
c.set(Calendar.HOUR, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
Log.d(TAG, c.getTime().toString());
return c;
}
Calendar c = calendar.getInstance();
and DatePickerDialog d
#Override
public void onDateSet(DatePicker view,int Year,int mont of Year,int day of month){
Toast
c.get(Calendar.Year),c.get(Calendar.Month),c.get(Calendar.Day_of_Month);
d.show
this code is to find week from selected date,it's proper work.
Calendar date1 = Calendar.getInstance();
Calendar date2 = Calendar.getInstance();
date1.clear();
date1.set(Integer.parseInt(selected_year), Integer.parseInt(selected_month), Integer.parseInt(selected_date)); // set date 1 (yyyy,mm,dd)
System.out.println("Selected Date==>>" + date1);
date2.clear();
date2.set(Integer.parseInt(current_year), Integer.parseInt(current_month), Integer.parseInt(current_date));
System.out.println("Current Date==>>" + date2);
long diff = date2.getTimeInMillis() - date1.getTimeInMillis();
float dayCount = (float) diff / (24 * 60 * 60 * 1000);
week = (int) (dayCount / 7);
if (week <= 0) {
Toast.makeText(this, "Sry System Error", Toast.LENGTH_SHORT).show();
System.out.println("Week==>>" + week);
test = false;
} else {
Toast.makeText(this, "Done", Toast.LENGTH_SHORT).show();
System.out.println("Week==>>" + week);
test = true;
}
I have created an activity in which there is a field for inserting birth date of the user. I have used a date picker to achieve this.
This is the source code of what I am doing:
// onclick dob edittext open date picker dialog
dob.setFocusableInTouchMode(false);
dob.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//open date picker
showDialog(DATE_DIALOG_ID);
}
});
//======================For picking birth day==========================
// Creating dialog
#Override
protected Dialog onCreateDialog(int id) {
Calendar c = Calendar.getInstance();
int cyear = c.get(Calendar.YEAR);
int cmonth = c.get(Calendar.MONTH);
int cday = c.get(Calendar.DAY_OF_MONTH);
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener, cyear, cmonth, cday);
}
return null;
}
private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
// onDateSet method
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
// String date_selected = String.valueOf(monthOfYear+1)+" /"
// +String.valueOf(dayOfMonth)+" /"
// +String.valueOf(year);
String date_selected = String.valueOf(dayOfMonth)+" /"
+String.valueOf(monthOfYear+1)+" /"
+String.valueOf(year);
//Toast.makeText(RegisterActivity.this, "Selected Date is ="+date_selected, Toast.LENGTH_SHORT).show();
dob.setText(date_selected);
}
};
//======================For picking birth day==========================
Now what I want to do is, to limit the date picker to particular year.
Like this:
int maxYear = c.get(Calendar.YEAR) - 15; // this year ( 2013 ) - 15 = 1998
int maxMonth = c.get(Calendar.MONTH);
int maxDay = c.get(Calendar.DAY_OF_MONTH);
int minYear = maxYear-49;
int minMonth = 0; // january
int minDay = 25;
What should I do to set the above mentioned bounding to the date picker?
//----------------Edit---------------------------
I have done something like this:
//======================For picking birth day==========================
// Creating dialog
#Override
protected Dialog onCreateDialog(int id) {
Calendar c = Calendar.getInstance();
maxYear = c.get(Calendar.YEAR) - 15; // this year ( 2013 ) - 15 = 1998
maxMonth = c.get(Calendar.MONTH);
maxDay = c.get(Calendar.DAY_OF_MONTH);
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener, maxYear, maxMonth, maxDay);
}
return null;
}
DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
int minYear = maxYear-49;
int minMonth = 0; // january
int minDay = 25;
public void onDateChanged(DatePicker view, int year, int monthOfYear,int dayOfMonth) {
Date current = new Date(year, monthOfYear, dayOfMonth);
Date minDate = new Date(minYear, minMonth, minDay);
Date maxDate = new Date(maxYear, maxMonth, maxDay);
if( current.getTime() < minDate.getTime() )
{
//set to minimum date
}else if( current.getTime() > maxDate.getTime() )
{
//Set to max Date
}
}
#Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
String date_selected = String.valueOf(dayOfMonth)+" /"
+String.valueOf(monthOfYear+1)+" /"
+String.valueOf(year);
//Toast.makeText(RegisterActivity.this, "Selected Date is ="+date_selected, Toast.LENGTH_SHORT).show();
dob.setText(date_selected);
}
};
//======================For picking birth day==========================
This is fixing the upper limit, but the lower limit or the minDate is not getting fixed! What is to be done?
Set OnDateChangedListener() For you DatePicker and inside onDateChanged function if the date set is greater than the decide limit if so DatePicker.updateDate(minYear, minMonth, minDay); use this method to reset it.
Date minDate = new Date(1990, 10, 25);
Date maxDate = new Date(2013, 4, 15);
OnDateChangedListener listener = new OnDateChangedListener() {
#Override
public void onDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
Date current = new Date(year, monthOfYear, dayOfMonth);
if( current.getTime() < minDate.getTime() )
{
//set to minimum date
}else if( current.getTime() > maxDate.getTime() )
{
//Set to max Date
}
}
};
YourDatePicker.init(2013, 4, 15, listener);
hi all how to generate dates if the start date and end date are provided in java?
like the following :
Ex : if the start date is 15-04-2012 and end date is 15-06-2012 having this i want dates to be like the following and the list should omit saturday and sunday
1.15-04-2012,
2.16-04-2012,
3.17-04-2012,
.
.
.
.
.
.
15-06-2012
I have done like the following but it will generate for one month if the date range is of same month.
`
public static ConcurrentHashMap<String, String> getWorkingDaysMap(int year, int month, int day){
int totalworkingdays=0,noofdays=0;
String nameofday = "";
ConcurrentHashMap<String,String> workingDaysMap = new ConcurrentHashMap<String,String>();
Map<String,String> holyDayMap = new LinkedHashMap<String,String>();
noofdays = findNoOfDays(year,month,day);
for (int i = 1; i <= noofdays; i++) {
Date date = (new GregorianCalendar(year,month - 1, i)).getTime(); // year,month,day
SimpleDateFormat f = new SimpleDateFormat("EEEE");
nameofday = f.format(date);
String daystr="";
String monthstr="";
if(i<10)daystr="0";
if(month<10)monthstr="0";
String formatedDate = daystr+i+"/"+monthstr+month+"/"+year;
if(!(nameofday.equals("Saturday") || nameofday.equals("Sunday"))){
workingDaysMap.put(formatedDate,formatedDate);
totalworkingdays++;
}
}
return workingDaysMap;
}
So please do advice me how to go about.
Regards
Tony
int noOfDaysBetween = 5;
Calendar cal = Calendar.getInstance();
cal.setTime(startDate);
for(int index = 0 ; index < noOfDaysBetween; index++){
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
if( dayOfWeek!=Calendar.SUNDAY && dayOfWeek!=Calendar.SATURDAY) {
System.out.println(cal.getTime());
}
cal.add(Calendar.DATE, 1);
}
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
//15-04-2012
calendar.set(Calendar.DAY_OF_MONTH, 15);
calendar.set(Calendar.YEAR, 2012);
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MONTH, 3);
Date start = calendar.getTime();
//15-06-2012
calendar.set(Calendar.MONTH, 5);
Date end = calendar.getTime();
calendar.setTime(start);
Date d = null;
while((d = calendar.getTime()).before(end) || d.equals(end)) {
int day = calendar.get(Calendar.DAY_OF_WEEK);
if (day != Calendar.SATURDAY && day != Calendar.SUNDAY) {
System.out.println(d);
}
calendar.add(Calendar.DAY_OF_MONTH, 1);
}
}
I prefer usage of LocalDate.
import java.time.DayOfWeek;
import java.time.LocalDate;
public class Game {
public static void main(String[] args) {
LocalDate start = LocalDate.of(2018, 6, 1);
LocalDate end = LocalDate.of(2018, 8, 1);
LocalDate d = start;
while(d.compareTo(end) <= 0) {
if (d.getDayOfWeek() != DayOfWeek.SATURDAY && d.getDayOfWeek() != DayOfWeek.SUNDAY) {
System.out.println(d);
}
d = d.plusDays(1);
}
}
}
use the following joda-time
import org.joda.time.DateTimeConstants;
import org.joda.time.LocalDate;
public class DatesexcludingWeekend {
public static void main(String[] args) {
final LocalDate start = new LocalDate(2012, 06, 15);
final LocalDate end = new LocalDate(2012, 07, 14);
LocalDate weekday = start;
if (start.getDayOfWeek() == DateTimeConstants.SATURDAY|| start.getDayOfWeek() == DateTimeConstants.SUNDAY) {
weekday = weekday.plusWeeks(1).withDayOfWeek(DateTimeConstants.MONDAY);
}
while (weekday.isBefore(end)) {
System.out.println(weekday);
if (weekday.getDayOfWeek() == DateTimeConstants.FRIDAY)
weekday = weekday.plusDays(3);
else
weekday = weekday.plusDays(1);
}
}