Calendar and DateFormat

J

John W. Kennedy

So howcum Calendar and DateFormat are so unfriendly to each other?

--
John W. Kennedy
"You can, if you wish, class all science-fiction together; but it is
about as perceptive as classing the works of Ballantyne, Conrad and W.
W. Jacobs together as the 'sea-story' and then criticizing _that_."
-- C. S. Lewis. "An Experiment in Criticism"
* TagZilla 0.066 * http://tagzilla.mozdev.org
 
C

ck

So howcum Calendar and DateFormat are so unfriendly to each other?

--
John W. Kennedy
"You can, if you wish, class all science-fiction together; but it is
about as perceptive as classing the works of Ballantyne, Conrad and W.
W. Jacobs together as the 'sea-story' and then criticizing _that_."
-- C. S. Lewis. "An Experiment in Criticism"
* TagZilla 0.066 *http://tagzilla.mozdev.org

How?
 
J

John W. Kennedy


How not?

import java.text.*;
import java.util.*;

public final class DateStuff {

private static final DateFormat df =
new SimpleDateFormat("EEEE, MMMM dd, yyyy");

public static void main(String[] args) {
final Calendar c =
new GregorianCalendar(2000, Calendar.JANUARY, 1);
c.add(Calendar.DATE, -9999);
final Date d = new Date(c.get(Calendar.YEAR),
c.get(Calendar.MONTH),
c.get(Calendar.DATE));
System.out.println(df.format(d));
}

}

Not only clunky, but it produces a warning (deprecation) message.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

John said:
import java.text.*;
import java.util.*;

public final class DateStuff {

private static final DateFormat df =
new SimpleDateFormat("EEEE, MMMM dd, yyyy");

public static void main(String[] args) {
final Calendar c =
new GregorianCalendar(2000, Calendar.JANUARY, 1);
c.add(Calendar.DATE, -9999);
final Date d = new Date(c.get(Calendar.YEAR),
c.get(Calendar.MONTH),
c.get(Calendar.DATE));
System.out.println(df.format(d));
}

}

Not only clunky, but it produces a warning (deprecation) message.

Yes.

It is deprecated to use the Date constructor with arguments.

import java.text.*;
import java.util.*;

public final class DateStuff {
private static final DateFormat df = new SimpleDateFormat("EEEE,
MMMM dd, yyyy");
public static void main(String[] args) {
Calendar c = new GregorianCalendar(2000, Calendar.JANUARY, 1);
c.add(Calendar.DATE, -9999);
System.out.println(df.format(c.getTime()));
}
}

is both simpler and not deprecated.

Arne
 
J

John W. Kennedy

Arne said:
John said:
import java.text.*;
import java.util.*;

public final class DateStuff {

private static final DateFormat df =
new SimpleDateFormat("EEEE, MMMM dd, yyyy");

public static void main(String[] args) {
final Calendar c =
new GregorianCalendar(2000, Calendar.JANUARY, 1);
c.add(Calendar.DATE, -9999);
final Date d = new Date(c.get(Calendar.YEAR),
c.get(Calendar.MONTH),
c.get(Calendar.DATE));
System.out.println(df.format(d));
}

}

Not only clunky, but it produces a warning (deprecation) message.

Yes.

It is deprecated to use the Date constructor with arguments.

import java.text.*;
import java.util.*;

public final class DateStuff {
private static final DateFormat df = new SimpleDateFormat("EEEE,
MMMM dd, yyyy");
public static void main(String[] args) {
Calendar c = new GregorianCalendar(2000, Calendar.JANUARY, 1);
c.add(Calendar.DATE, -9999);
System.out.println(df.format(c.getTime()));
}
}

is both simpler and not deprecated.

Ah! In order to get a Date from a Calendar, I use "getTime".

Right.

Razzafrazzin' germbelstwithin' flollilocks!

Heigh-ho!

Many thanks....

--
John W. Kennedy
"The grand art mastered the thudding hammer of Thor
And the heart of our lord Taliessin determined the war."
-- Charles Williams. "Mount Badon"
* TagZilla 0.066 * http://tagzilla.mozdev.org
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top