Results 1 to 2 of 2
  1. #1
    senzacionale is offline Member
    Join Date
    Dec 2007
    Posts
    1
    Rep Power
    0

    Default date one month back

    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    java.util.Date date = new java.util.Date();
    String datetime= dateFormat.format(date);

    like this i get current date. How i can get date one months back?

    regards

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    Date date = new Date();
    System.out.println("date = " + dateFormat.format(date));
    // get date one months back
    Calendar calendar = Calendar.getInstance();
    System.out.println("current calendar time = " +
                        dateFormat.format(calendar.getTime()));
    calendar.add(Calendar.MONTH, -1);
    System.out.println("calendar one month back = " +
                        dateFormat.format(calendar.getTime()));

Similar Threads

  1. Month and year program code!!!!HELP PLEASE!!!
    By chitwood in forum New To Java
    Replies: 4
    Last Post: 10-13-2010, 02:21 PM
  2. Difference between current date and anothe date
    By vijay balusamy in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 05:15 PM
  3. Datepicker Calender - month change event - jquery
    By rmpatel101 in forum Advanced Java
    Replies: 0
    Last Post: 04-02-2008, 07:42 PM
  4. Current month
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-07-2008, 09:40 AM
  5. Replies: 0
    Last Post: 01-04-2008, 10:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •