Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

Calendar and DateFormat

Thread view: 
John W. Kennedy - 12 Mar 2007 20:57 GMT
So howcum Calendar and DateFormat are so unfriendly to each other?

Signature

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

ck - 12 Mar 2007 21:18 GMT
> So howcum Calendar and DateFormat are so unfriendly to each other?
>
> --
> John W. Kennedy

How?

--
Ck
John W. Kennedy - 13 Mar 2007 01:54 GMT
>> So howcum Calendar and DateFormat are so unfriendly to each other?

> How?

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.

Signature

John W. Kennedy
"Sweet, was Christ crucified to create this chat?"
  -- Charles Williams.  "Judgement at Chelmsford"
* TagZilla 0.066 * http://tagzilla.mozdev.org

Arne Vajhøj - 13 Mar 2007 02:00 GMT
> import java.text.*;
> import java.util.*;
[quoted text clipped - 17 lines]
>
> 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
John W. Kennedy - 13 Mar 2007 03:58 GMT
>> import java.text.*;
>> import java.util.*;
[quoted text clipped - 36 lines]
>
> 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....

Signature

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

Roedy Green - 13 Mar 2007 19:37 GMT
On Mon, 12 Mar 2007 20:54:55 -0400, "John W. Kennedy"
<jwkenne@attglobal.net> wrote, quoted or indirectly quoted someone who
said :

>new Date(c.get(Calendar.YEAR),
>           c.get(Calendar.MONTH),
>           c.get(Calendar.DATE));

Date is the lemon of Java.   The only way to fix the problem was to
deprecate most of Date. It has only a tiny few legit uses left.

see http://mindprod.com/jgloss/gotchas.html#DATE
Signature

Canadian Mind Products, Roedy Green, http://mindprod.com
Priorities: Prevent global climate destabilisation. End both wars. Prepare for oil shortages.

ck - 12 Mar 2007 22:09 GMT
> So howcum Calendar and DateFormat are so unfriendly to each other?
>
[quoted text clipped - 5 lines]
>    -- C. S. Lewis.  "An Experiment in Criticism"
> * TagZilla 0.066 *http://tagzilla.mozdev.org

How?

--
Ck
a24900@googlemail.com - 12 Mar 2007 22:41 GMT
> So howcum Calendar and DateFormat are so unfriendly to each other?

Only for trolls who don't read the API documentation.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.