Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DateFormat;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.Scanner;
- public class DateAfter1000Days{
- public static Date StringToDate(String dob) throws ParseException{
- //Instantiating the SimpleDateFormat class
- SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
- //Parsing the given String to Date object
- Date date = formatter.parse(dob);
- System.out.println("Date object value: "+date);
- return date;
- }
- public static void main(String args[]) throws ParseException {
- // Creating calendar objects
- Calendar calndr1
- = (Calendar)Calendar.getInstance();
- String pattern = "dd-MM-yyyy";
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
- //Reading name and date of birth from the user
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter your date of birth (dd-MM-yyyy): ");
- String dob = sc.next();
- //Converting String to Date
- DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
- Date date = simpleDateFormat.parse(dob);
- calndr1.setTime(date);
- calndr1.add(Calendar.DATE, 1000);
- System.out.println(dateFormat.format(calndr1.getTime()));
- }
- }
Add Comment
Please, Sign In to add comment