Converting a Date Object to a GregorianCalendar Object

Discussion in 'Java' started by KevinSimonson, Jun 25, 2011.

  1. I can go from a GregorianCalendar object to a Date object with the
    method getTime(). Is there any way to go from a Date object to a
    GregorianCalendar object? I haven't been able to find a way to do
    it. If there isn't any way to do it, why isn't there any way to do
    it?

    This is kind of frustrating. I'm testing some code that stores times
    in Date objects. I can set those objects to certain dates with
    setYear(), setMonth(), and setDate(), but those methods are all
    deprecated, and so I thought it would be better programming to create
    a GregorianCalendar object and convert it to a Date.

    But then to check that the Date value is actually getting set right, I
    need to convert it back to a GregorianCalendar object, and I don't see
    any way to do that. I could use the Date methods getYear(),
    getMonth(), and getDate(), and bypass GregorianCalendar, but once
    again all three of those methods are deprecated. There doesn't appear
    to be a way to check these Date objects without using deprecated
    methods! Anybody have any thoughts on this?

    Kevin Simonson
    KevinSimonson, Jun 25, 2011
    #1
    1. Advertising

  2. KevinSimonson

    Jeff Higgins Guest

    On 06/24/2011 07:54 PM, KevinSimonson wrote:
    > I can go from a GregorianCalendar object to a Date object with the
    > method getTime(). Is there any way to go from a Date object to a
    > GregorianCalendar object?


    Calender.setTime(Date date)?
    Jeff Higgins, Jun 25, 2011
    #2
    1. Advertising

  3. KevinSimonson

    Roedy Green Guest

    On Fri, 24 Jun 2011 16:54:32 -0700 (PDT), KevinSimonson
    <> wrote, quoted or indirectly quoted someone who
    said :

    >I can go from a GregorianCalendar object to a Date object with the
    >method getTime(). Is there any way to go from a Date object to a
    >GregorianCalendar object? I haven't been able to find a way to do
    >it. If there isn't any way to do it, why isn't there any way to do
    >it?


    see http://mindprod.com/jgloss/calendar.html
    for various recipes.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    One of the great annoyances in programming derives from the irregularity
    of English spelling especially when you have international teams.
    I want to find a method or variable, but I don't know precisely
    how its is spelled or worded. English is only approximately phonetic.
    Letters are randomly doubled. The dictionary often lists variant spellings.
    British, Canadian and American spellings differ.I would like to see an
    experiment where variable names were spelled in a simplified English, where
    there were no double letters.I also think you could add a number of rules
    about composing variable names so that a variable name for something would
    be highly predictable. You would also need automated enforcement of the
    rules as well as possible.
    Roedy Green, Jun 25, 2011
    #3
  4. On Jun 24, 6:43 pm, Jeff Higgins <> wrote:
    > On 06/24/2011 07:54 PM, KevinSimonson wrote:
    >
    > > I can go from a GregorianCalendar object to a Date object with the
    > > method getTime().  Is there any way to go from a Date object to a
    > > GregorianCalendar object?

    >
    > Calender.setTime(Date date)?


    Thanks! This worked just fine!

    Kevin Simonson
    KevinSimonson, Jun 25, 2011
    #4
  5. KevinSimonson

    Lew Guest

    On 06/25/2011 05:29 PM, KevinSimonson wrote:
    > On Jun 24, 6:43 pm, Jeff Higgins<> wrote:
    >> On 06/24/2011 07:54 PM, KevinSimonson wrote:
    >>
    >>> I can go from a GregorianCalendar object to a Date object with the
    >>> method getTime(). Is there any way to go from a Date object to a
    >>> GregorianCalendar object?

    >>
    >> Calender.setTime(Date date)?

    >
    > Thanks! This worked just fine!


    Learn to use the API docs.
    <http://download.oracle.com/javase/6/docs/api/java/util/Calendar.html>

    --
    Lew
    Honi soit qui mal y pense.
    http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
    Lew, Jun 26, 2011
    #5
  6. In comp.lang.java.programmer message <area0711fsrrpi4a93sfl87gjj8l6ebksr
    @4ax.com>, Fri, 24 Jun 2011 18:35:57, Roedy Green <see_website@mindprod.
    com.invalid> posted:

    > --
    > ...
    >I would like to see an
    >experiment where variable names were spelled in a simplified English, where
    >there were no double letters.


    Personally, I think that variable names, if semantically significant,
    *should* be spelt wrongly, since in that case a global search can
    discriminate between variable names and words of ordinary text.

    For that, it helps to be writing pages in Foreign, since programing
    words are commonly in English.

    --
    (c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
    Web <http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
    That reminds me. Are there are any Quebecois astronomers here with
    an interest in orbital dynamics?
    Dr J R Stockton, Jun 27, 2011
    #6
  7. KevinSimonson

    Lew Guest

    Roedy Green posted:
    >> ...
    >> I would like to see an
    >> experiment where variable names were spelled in a simplified English, where
    >> there were no double letters.



    "Simplified spelling brought about sun-spots, the San Francisco earthquake,
    and the recent business depression, which we would never have had if spelling
    had been left all alone."

    -- Mark Twain
    http://en.wikisource.org/wiki/The_Alphabet_and_Simplified_Spelling

    --
    Lew
    <http://triptronix.net/ishbadiddle/archives/2009/07/22/18.19.15/>
    Lew, Jun 28, 2011
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Manoj Nair
    Replies:
    4
    Views:
    21,333
    Manoj Nair
    Sep 4, 2003
  2. Nigel Wade
    Replies:
    10
    Views:
    823
    P.Hill
    Nov 24, 2003
  3. TT \(Tom Tempelaere\)

    Convert from java.sql.Date to GregorianCalendar

    TT \(Tom Tempelaere\), Jan 29, 2004, in forum: Java
    Replies:
    17
    Views:
    50,067
    P.Hill
    Feb 1, 2004
  4. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,251
    Michael Borgwardt
    May 30, 2004
  5. Erwin Moller
    Replies:
    80
    Views:
    8,635
    Erwin Moller
    Aug 27, 2004
Loading...

Share This Page