Results 1 to 2 of 2
  1. #1
    jboy is offline Member
    Join Date
    Aug 2009
    Posts
    56
    Rep Power
    0

    Default GregorianCalender class

    Hi,

    How can I use a static date attribute to store a specific date for example,
    1/1/2008 using GregorianCalender class? Also, I need to add this date to the user's date when they enter day, month and year in integar. After all of this,
    I need to show the final date in the format day/month/year. Any help will be much appreciated.

    Thanks in advance.

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Well, you could store the date in long format, then use the setTime method inherited from Calendar. For example:
    Java Code:
    import java.util.Date;
    import java.util.GregorianCalendar;
    
    public class PointInTime {
        static long time = 1252247661203L;
        static GregorianCalendar cal;
    
        static{
            cal = new GregorianCalendar();
        }
    
        public static String getTime(){
            cal.setTime(new Date(time));
            return cal.get(cal.HOUR_OF_DAY)+":"+cal.get(cal.MINUTE)+":"+cal.get(cal.SECOND);
        }
    
        public static void main(String[] args) {
            System.out.println(getTime());
        }
    }
    I included a main method for testing -- Is this along the lines you were thinking of? Any time the getTime method is called, it will always return the same point in time, stored in the long value. You can use the Date class to convert a traditional date/time into a long value, or you can just store a Date object.

Similar Threads

  1. Replies: 7
    Last Post: 05-06-2009, 01:42 PM
  2. Replies: 8
    Last Post: 03-21-2009, 10:34 AM
  3. Calling a method on original class from created class
    By kpedersen in forum Advanced Java
    Replies: 4
    Last Post: 08-20-2008, 01:25 AM
  4. Replies: 0
    Last Post: 05-13-2008, 07:16 AM
  5. Replies: 0
    Last Post: 04-02-2008, 08:04 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
  •