Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Converting a Date Object to a GregorianCalendar Object

Reply
Thread Tools

Converting a Date Object to a GregorianCalendar Object

 
 
KevinSimonson
Guest
Posts: n/a
 
      06-24-2011
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
 
Reply With Quote
 
 
 
 
Jeff Higgins
Guest
Posts: n/a
 
      06-25-2011
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)?
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      06-25-2011
On Fri, 24 Jun 2011 16:54:32 -0700 (PDT), KevinSimonson
<(E-Mail Removed)> 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.
 
Reply With Quote
 
KevinSimonson
Guest
Posts: n/a
 
      06-25-2011
On Jun 24, 6:43*pm, Jeff Higgins <(E-Mail Removed)> 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
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      06-26-2011
On 06/25/2011 05:29 PM, KevinSimonson wrote:
> On Jun 24, 6:43 pm, Jeff Higgins<(E-Mail Removed)> 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/wikipedi.../c/cf/Friz.jpg
 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      06-27-2011
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?
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      06-27-2011
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_Al...ified_Spelling

--
Lew
<http://triptronix.net/ishbadiddle/archives/2009/07/22/18.19.15/>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What a mess: Date, milliseconds, GregorianCalendar Erwin Moller Java 80 08-27-2004 11:05 AM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Convert from java.sql.Date to GregorianCalendar TT \(Tom Tempelaere\) Java 17 02-01-2004 01:04 AM
GregorianCalendar applet and StreamCorruptedException Nigel Wade Java 10 11-24-2003 05:15 PM
GregorianCalendar and how to subtract MONTH from a date. Manoj Nair Java 4 09-04-2003 05:49 AM



Advertisments