Results 1 to 7 of 7
  1. #1
    CuppaCoffee's Avatar
    CuppaCoffee is offline Member
    Join Date
    Jan 2012
    Location
    Canada
    Posts
    80
    Rep Power
    0

    Default How To Get The Date

    Salutations, my programming friends. It's been a while since I've made a thread. Been taking a break from life.

    Quick question, how can you get Java to return the current date & time? I've heard of the Date (which has been deprecated) and Calendar classes, but you have to input information before it outputs date details to you. Is there a way for java to return the current date? Answers will be much appreciated!

  2. #2
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    393
    Rep Power
    4

    Default Re: How To Get The Date

    Have a look at the API: Calendar (Java Platform SE 6)

  3. #3
    CuppaCoffee's Avatar
    CuppaCoffee is offline Member
    Join Date
    Jan 2012
    Location
    Canada
    Posts
    80
    Rep Power
    0

    Default Re: How To Get The Date

    The API is very convoluted, too detailed for me to find any brief information I'm looking for. I was wondering if any members here had any tips or methods they have for doing something so simple.

  4. #4
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    393
    Rep Power
    4

    Default Re: How To Get The Date

    In the third paragraph of the API, it says:

    Like other locale-sensitive classes, Calendar provides a class method, getInstance, for getting a generally useful object of this type. Calendar's getInstance method returns a Calendar object whose calendar fields have been initialized with the current date and time:

    Java Code:
    Calendar rightNow = Calendar.getInstance();
    As for how to get the data out of the Calendar object, have a look at the get method.

  5. #5
    CuppaCoffee's Avatar
    CuppaCoffee is offline Member
    Join Date
    Jan 2012
    Location
    Canada
    Posts
    80
    Rep Power
    0

    Default Re: How To Get The Date

    Ahh, I was looking at the .getInstance() method, but I was outputting that by itself. Using that with the .getTime() method seems to generally give me a bit of what I was looking for.. I guess API's can be helpful when looked through properly. I still think they're overly complex though.

    Thanks for the help, Toll!

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,275
    Rep Power
    6

    Default Re: How To Get The Date

    Quote Originally Posted by CuppaCoffee View Post
    Been taking a break from life.
    ... so you were dead!?!? What was that like?

    I've heard of the Date (which has been deprecated)
    You are very much mistaken.

    Is there a way for java to return the current date?
    Of course there is; this is not the question you want to ask. You want to ask HOW so might as well ask that question right away. And since you are too impatient to take 2 minutes to scan through the javadoc, a google for "java calendar example" would have probably netted you the answer in less time it took you to post this thread.

    But impatience is highly destructive to programming, I'd work on that if I were you. Or perhaps drink less coffee?

  7. #7
    CuppaCoffee's Avatar
    CuppaCoffee is offline Member
    Join Date
    Jan 2012
    Location
    Canada
    Posts
    80
    Rep Power
    0

    Default Re: How To Get The Date

    Well, will you look at that. The first poor attempt at trolling I've seen on this site. I guess there's a first for everything.

Similar Threads

  1. Replies: 5
    Last Post: 02-16-2012, 10:26 AM
  2. Replies: 4
    Last Post: 07-27-2011, 12:57 PM
  3. Replies: 2
    Last Post: 05-12-2011, 05:52 PM
  4. Compare date input to database with current date
    By hungleon88 in forum Advanced Java
    Replies: 2
    Last Post: 11-25-2008, 09:10 AM
  5. Creating a Gregorian Calendar using a Date object gives date - 1
    By prachi_goliwadekar in forum New To Java
    Replies: 1
    Last Post: 05-08-2008, 09:32 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
  •