T
TT \(Tom Tempelaere\)
Hi,
How do I convert from java.sql.Date to GregorianCalendar?
Thanks,
Tom Tempelaere
How do I convert from java.sql.Date to GregorianCalendar?
Thanks,
Tom Tempelaere
TT said:How do I convert from java.sql.Date to GregorianCalendar?
P.Hill said:Calendar.setTime( Date );
Just an old weird API name to confuse you.
-Paul
P.Hill said:Calendar.setTime( Date );
Just an old weird API name to confuse you.
-Paul
P.Hill said:Calendar.setTime( Date );
Just an old weird API name to confuse you.
-Paul
TT said:So I should construct default GregorianCalendar, and then call setTime?
Date dt = /*...*/;
GregorianCalendar gc = new GregorianCalendar();
gc.setTime( dt.getTime() );
TT said:I what date format would you supply dates to a client (in a client/server
model)? Calendar or Date?
TT said:Does this work with TimeStamp (so that it doesn't lose the nano's)?
TT said:I what date format would you supply dates to a client (in a client/server
model)? Calendar or Date?
Thomas said:As integer timestamps, where 0 == 1970-01-01 00:00H GMT.
Probably
amended with a timezone identification of the place of origin, solely to
be used for display purposes, but never ever a timezone-relative date
value.
P.Hill said:If you are NOT dealing with issues of displaying time in timezone other
than that of the client, and you just need to display a time in the timezone of
the user then I would use the much more compact binary representation of date
and time, the java.util.Date.
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 would suggest you also look into SimpleDateFormat which takes
a date and makes a String. This is usually what you'll need in
a client application.
-Paul
P.Hill said:What do you mean, does it work?
I think you need to learn to understand objects and the docs for those
objects.
Try:
http://java.sun.com/j2se/1.4.2/docs/api/
Can you find some method that allows you to send a TimeStamp into
a calendar?
Can you find any discussion of nanoseconds in Calendar or DateFormat?
Are you really interested in making a String out of a timestamp?
Why? What are you going to do with it?
TT (Tom Tempelaere) said:The specific server routine returns a vector of objects (history). The
objects have a few dates as members, and these should be easily convertible
to strings (displaying), and easily to be used for comparison (post
selection operations - server side or client side) etc.
TT said:TimeStamp derives from java.util.Date. I just wondered if it took
nanoseconds into account. Guess not.
My colleague is using that, I wouldn't know why either.
P.Hill said:TT (Tom Tempelaere) wrote: [...]
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
So I should construct default GregorianCalendar, and then call setTime?
Tony said:No.
Call Calendar.getInstance()
This takes into account the fact that the VM is running in an environment
where a Gregorian Calendar is used (i.e. earth).
Move your software to another planet where the year is not 365.24 days long
and the software falls over.
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.