| | |
week in year....calculation
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
i am designing a page where the user enters the start date for a uni session say
04/02/2008 in dd/mm/yyyy format and then the user selects the duration for the session in weeks, say 22.
our system needs to calculate the end date for the session by adding 22 weeks to the start date...i can do this in real life by looking up a calender that shows week of the year....how do we do it programming.
we are using java/jsp, any suggestions please.
04/02/2008 in dd/mm/yyyy format and then the user selects the duration for the session in weeks, say 22.
our system needs to calculate the end date for the session by adding 22 weeks to the start date...i can do this in real life by looking up a calender that shows week of the year....how do we do it programming.
we are using java/jsp, any suggestions please.
Mathematics possesses not only truth, but supreme beauty …
Bertrand Russell
Bertrand Russell
Use the SimpleDateFormat class to parse the string into a Date object. Feed that Date object to the instance of the Calendar object and use it's function roll() to do the dirty work for you. Something along the lines of:
JSP Syntax (Toggle Plain Text)
public class DateHelper { public static void main(String args[]) throws ParseException { String dateStr = "13/01/2008"; SimpleDateFormat sdf = new SimpleDateFormat("DD/mm/yyyy"); Date dt = sdf.parse(dateStr); Calendar cal = Calendar.getInstance(); cal.setTime(dt); cal.roll(Calendar.WEEK_OF_YEAR, 22); //add 22 weeks Date newDt = cal.getTime(); System.out.println("Training from " + dt + " to " + newDt); } }
I don't accept change; I don't deserve to live.
![]() |
Similar Threads
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- :-) C++ Developer - Financial / Trading company London, Permanent, London (Software Development Job Offers)
- Cannot find sybol Constructor and Methods (Java)
- EasterDay (C++)
- Date calculation and checking. (VB.NET)
- leap year calculation (ASP)
- How to round down (remainders?) in C (C)
Other Threads in the JSP Forum
- Previous Thread: How to encrypt and decrypt a password?
- Next Thread: Help in sessions...
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial update video web






