> 1. Get today's date.
Date today = new Date();
> 2. Using the current date, get the date of the first day of the week
> (Sunday), and I think I might need to know how to get the end date
> also.
So you're not going to create an i8n-aware application?
Sunday isn't the first day of the week everwhere (e.g.
it's monday in Germany). Here is an (untested) solution:
DateTimeConstants constants = LocaleInfo.getCurrentLocale().getDateTimeConstants();
int firstDay = Integer.parseInt(constants.firstDayOfTheWeek()) - 1;
int offset = firstDay - date.getDay();
date.setDate(date.getDate() + offset);
> 3. How to Add and subtract a number of days to a date.
date.setDate(date.getDate() + days);
> 4. I need to know how to parse all the above questions information
> into a string.
By "parse" do you mean format?
Use the various ways DateTimeFormat offers.
> Off the top of my head, that's what I'm trying to do. 1 More question:
> 5. Would it improve performance while handling a start date and an end
> date for an event, instead of keeping an end date, calculating the
> duration that the event would last, rather than calculating the date?
> Would it even be worth it? (A friend recommended this)
If the event happens during a change in daylight saving times,
you will end up with wrong times.
> 6. Are we seeing any updates coming for working with dates? I'm
> currently using GWT 2.03.
I'm not a developer, so I can't say anything about that, but
if you're sugessting a (maybe restricted) implementation of
Calender, here is a +1 by me, because above methods in Date
are all deprecated since JDK 1.1, so I really hate to use them,
even in a GWT client-class where that doesn't matter much.
Regards, Lothar
> Lothar, your code works (at least for the current date) :
It should work for every date, just instantiate Date with
one of the non-default constructors.
> However, I can't find a way to get the first day of the week for any
> given date. For instance, lets say I wanted to find the first day of
> the week for September 27th, 2010, how would I do that?
Using the deprecated constructor of Date:
Date date = new Date(110, 08, 27);
You can also use the date-parsing classes of GTW to parse
a string to a date.
Regards, Lothar
> As for performing operations on Dates such as adding days I usually
> use the getTime method (this returns the Date as a long representing
> the number of milliseconds that have passed since January 1, 1970,
> 00:00:00 GMT) and operate on the dates as a long. So for example if I
> want to add a day I just add (24*60*60*1000) to the long then create a
> new Date object.
you're not the first giving this "advice". This way of adding
days is plain wrong. In countries with e.g. CEST adding 24 hours
to 10/30/2010 03:01 AM will result to 10/31/2010 02:01 AM.
So stop doing this kind of arithmetic and use Calendar on
server-side and wait (as I do) that there will some equal
kind of thing on the client side at some day. If I would
have the time to implement it, I'd program it for myself.
Regards, Lothar
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.