Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Converting a Date Object to a GregorianCalendar Object (http://www.velocityreviews.com/forums/t750489-converting-a-date-object-to-a-gregoriancalendar-object.html)

KevinSimonson 06-24-2011 11:54 PM

Converting a Date Object to a GregorianCalendar Object
 
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

Jeff Higgins 06-25-2011 12:43 AM

Re: Converting a Date Object to a GregorianCalendar Object
 
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)?

Roedy Green 06-25-2011 01:35 AM

Re: Converting a Date Object to a GregorianCalendar Object
 
On Fri, 24 Jun 2011 16:54:32 -0700 (PDT), KevinSimonson
<kvnsmnsn@hotmail.com> 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.

KevinSimonson 06-25-2011 09:29 PM

Re: Converting a Date Object to a GregorianCalendar Object
 
On Jun 24, 6:43*pm, Jeff Higgins <j...@invalid.invalid> 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

Lew 06-26-2011 06:06 PM

Re: Converting a Date Object to a GregorianCalendar Object
 
On 06/25/2011 05:29 PM, KevinSimonson wrote:
> On Jun 24, 6:43 pm, Jeff Higgins<j...@invalid.invalid> 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

Dr J R Stockton 06-27-2011 08:36 PM

Re: Converting a Date Object to a GregorianCalendar Object
 
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?

Lew 06-27-2011 11:38 PM

Re: Converting a Date Object to a GregorianCalendar Object
 
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/>


All times are GMT. The time now is 03:33 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.