on 05-12-2010 2:01 PM
Input is a Date(For example: 2010/03/12) in String format.
I need to extract the last day of that week and return it as a string output.
For example if input is 2010/03/12 and thatu2019s a Thursday my output should be 2010/03/14 i.e Saturdayu2019s date.
Similarly I need to extract last day of month too.
Thanks in advance
Soumen...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think i had the same source when I needed that function
Here the last day in a month:
String yearS = var1.substring(1,5);
int year = Integer.parseInt(yearS);
// get month (note: January = 0)
String monthS = var1.substring(6,8);
int month = Integer.parseInt(monthS) - 1;
// determine last day of month
Calendar calendar = Calendar.getInstance();
calendar.set(year,month,1);
int lastDate = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
String lastDateS = Integer.toString(lastDate);
String dateS = yearS + monthS + lastDateS;
return dateS;
hi Soumen,
see this code : [http://www.kodejava.org/examples/134.html|http://www.kodejava.org/examples/134.html]
or this one:
[http://www.roseindia.net/java/java-get-example/get-last-day-month.shtml|http://www.roseindia.net/java/java-get-example/get-last-day-month.shtml]
that helped me.
Regards.
Mickael
Hi,
I did not develop this one... but just use "search" button on roseindia and you will have the answer (I think):
[http://www.roseindia.net/java/beginners/DayOfYearToDayOfWeek.shtml|http://www.roseindia.net/java/beginners/DayOfYearToDayOfWeek.shtml]
and do not forget that Google is your friend...
do a research with : Java last day of week, and you have plenty of examples.
)
Thanks.
P.S: Say us when you will solved your problem.
You can also try this...
Under Imports java.util.Date;
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
String lastday = "" + cal.getTime();
String dlvday = lastday.substring(0,3);
String dlvdate = lastday.substring(8,10);
String dateofdelivery = dlvdate + lastday.substring(4,7) + lastday.substring(24,28);
return dateofdelivery;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.