Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How do you create Date objects?

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    26
    My Mood
    Where
    Thanks
    8
    Thanked 1 Time in 1 Post

    Default How do you create Date objects?

    Let's say i have this code:

    import java.util.Date;
     
    public class MyDate {
        Date newDate;
     
        public MyDate(Date date) {
     
            newDate = date;
        }
    }
    How do i instantiate this class?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How do you create Date objects?

    You use the new keyword. Recommended reading: Creating Objects (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

    PS- Make sure you use standard naming conventions. Class names start with an upper-case letter.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Aug 2013
    Posts
    26
    My Mood
    Where
    Thanks
    8
    Thanked 1 Time in 1 Post

    Default Re: How do you create Date objects?

    Yeah, i know i need to use the new keyword.The confusion is in the constructor
    MyDate today = new MyDate(...with regards to my example,what goes in here?...);
    Strings don't work

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: How do you create Date objects?

    Consult the Date class for it's various constructors.

    --- Update ---

    Do take note that much of that class has been depreciated...

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How do you create Date objects?

    Quote Originally Posted by ojonugwa View Post
    Yeah, i know i need to use the new keyword.The confusion is in the constructor
    MyDate today = new MyDate(...with regards to my example,what goes in here?...);
    Strings don't work
    Without knowing your context (in the form of an SSCCE), I can't tell you exactly what goes there. I can tell you that a Date object goes there, and you can consult the API for different ways to create an instance of Date.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Compare two date objects
    By Kristenw17 in forum Object Oriented Programming
    Replies: 2
    Last Post: April 25th, 2013, 01:16 AM
  2. how to create multiple objects
    By dominco in forum What's Wrong With My Code?
    Replies: 8
    Last Post: November 6th, 2012, 08:12 AM
  3. Trying to create an array of stacks that contain objects
    By jadeclan in forum Collections and Generics
    Replies: 15
    Last Post: October 6th, 2012, 03:30 PM
  4. How to create a pointer type of effect for objects
    By zelalem in forum Object Oriented Programming
    Replies: 6
    Last Post: October 20th, 2010, 02:53 AM
  5. Create Objects on Demand?
    By Programmierer in forum Object Oriented Programming
    Replies: 5
    Last Post: July 7th, 2010, 01:13 PM