Re: Convert from java.sql.Date to GregorianCalendar
From: P.Hill (goodhill_at_xmission.com)
Date: 01/30/04
- Next message: RamRod: "Basic Struts question"
- Previous message: Hylander: "Re: Hashcode of primitive types"
- In reply to: TT \(Tom Tempelaere\): "Re: Convert from java.sql.Date to GregorianCalendar"
- Next in thread: TT \(Tom Tempelaere\): "Re: Convert from java.sql.Date to GregorianCalendar"
- Reply: TT \(Tom Tempelaere\): "Re: Convert from java.sql.Date to GregorianCalendar"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 29 Jan 2004 16:08:54 -0700
TT (Tom Tempelaere) wrote:
>>>A Calendar is a variation of a strategy pattern, it is the thing that
>>>contains the algorthms for taking day 28002 (or whatever the internal
>>>value for a day it) and changing it into something with Year-Month-Day
>>>components. It is very large compared to a Date.
>>I thought about using GregorianCalendar objects for
>>dates. Plus, no real conversion is necessary if the client (UI) needs a
>>gregoriancalendar.
You'll find that JSPs/JSTL/Struts/Swing etc. deal in Dates not Calendars.
Sending around a Calendar is like sending around a sort routine, when
what you really want to send around is a sorted list.
USE A DATE!
Any time you have a binary Date object you have to ask what time zone
you wish to display the value in (plus you sometimes need to worry about
language). Date does not have such features, so you create a GregorianCalendar
push the date in and ask for some fields back out.
But often you use SimpleDateFormat and just ask for a formatted string, which
will deal with Calendar for you.
>>Can you tell me how TimeStamp differs from Date for instance?
As the API says, it is a Date with a nanosecond field. The nanoseconds
replaces the milliseconds. It also is used to Identify to
the JDBC API that you have something which represents a TimeStamp.
Again, read the API.
Why do you think you want to use it in your program;
You might define you DB to contain such a thing, but you can always
ask the JDBC layer for a Date object and send that around.
Why is Date mostly deprecated? It is now intended to _hold_ a
binary date. Because ettting month day and year requires knowledge of
timezone and language, so all that knowledge is over in Calendar.
Does that make sense? If not just use it that way anyway.
Dates for in and out of GUIs, DBs and transport protocols (
for javaMail uses Dates also), while Calendar are
used when you or DateFormat wants to separate things into
separate month, day, year, etc. fields.
Does that make sense?
-Paul
- Next message: RamRod: "Basic Struts question"
- Previous message: Hylander: "Re: Hashcode of primitive types"
- In reply to: TT \(Tom Tempelaere\): "Re: Convert from java.sql.Date to GregorianCalendar"
- Next in thread: TT \(Tom Tempelaere\): "Re: Convert from java.sql.Date to GregorianCalendar"
- Reply: TT \(Tom Tempelaere\): "Re: Convert from java.sql.Date to GregorianCalendar"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|