Converting a Date Object to a GregorianCalendar Object

K

KevinSimonson

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
 
J

Jeff Higgins

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)?
 
R

Roedy Green

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.
 
D

Dr J R Stockton

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top