Results 1 to 5 of 5
  1. #1
    luigihs is offline Member
    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0

    Default java.util.Calendar

    Hello I having a hard time to understand this Calendar (Java 2 Platform SE 5.0) I want to set my own year, month and day, and this what I did

    Java Code:
    /**
     * Write a description of class Calendar here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    import java.util.Calendar;
    public class Date
    {
        private int year;
        private int month;
        private int date;
        private int hourOfDay;
        private DataForma DataForma;
        
          public static void main(String[] args) {
    
          // create a calendar
          Calendar cal = Calendar.getInstance();
    
          // print current time
          System.out.println("Current year is :" + cal.getTime());
          }
    
            public void set(int year,int month,int date) {
    
        }
         
        
    
    }
    Im using BlueJ but everytime that I click on void main(String[] args) it gives me the computer time please can somebody help me Im really new in java and I want to do set my own and date and then display in terminal

  2. #2
    luigihs is offline Member
    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0

    Default Re: java.util.Calendar

    Ah and I dont want this I know how to do it like this way
    Java Code:
    public static void main(String[] args) {
            Calendar cal = Calendar.getInstance();
            cal.set(2011, 11, 5, 43, 4); //Enter date here, Year, Month, Day, minute, second
            //the minute and second are optional
            System.out.println("Current year is :" + cal.getTime());
    
        }
    I want to have void form so I can type whatever date I want instead of putting in the code.

  3. #3
    hariharansrc is offline Member
    Join Date
    Jul 2011
    Posts
    4
    Rep Power
    0

    Default Re: java.util.Calendar

    You can use calendar setter methods for setting your own date and time. For example,


    Java Code:
    package cal;
    import java.util.Calendar;
    
    public class CalendarTest {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    Calendar cal=Calendar.getInstance();
    cal.set(1991, 12, 17, 12, 56);
    System.out.println(cal.getTime());
    	}
    }


    can be used to set the time
    Last edited by hariharansrc; 11-17-2012 at 09:38 AM.

  4. #4
    luigihs is offline Member
    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0

    Default Re: java.util.Calendar

    Yeah but is there anyway I cant set up by void method ? so Im not going to my code everytime that I want to change a date??

  5. #5
    hariharansrc is offline Member
    Join Date
    Jul 2011
    Posts
    4
    Rep Power
    0

    Default Re: java.util.Calendar

    Why you want another method? can you explain the reason?
    If you want to change you can get input date from the user using classes such as Scanner and BufferedReader. Is there any specific reason for not using setter method?

Similar Threads

  1. Replies: 1
    Last Post: 06-19-2012, 03:55 AM
  2. Replies: 0
    Last Post: 04-26-2012, 12:50 PM
  3. java.util
    By DuncanHollows in forum New To Java
    Replies: 2
    Last Post: 03-19-2012, 05:24 PM
  4. Replies: 4
    Last Post: 09-21-2011, 05:39 PM
  5. java.util
    By Java Tutorial in forum Java Tutorial
    Replies: 1
    Last Post: 02-07-2008, 02:46 PM

Posting Permissions

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