I want to get the date of a particular day of the week e.g Wednessday. i.e If today's date is 27th Friday, Wednessday would infact be the 25th .
I could achieve this by
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);
String thisWed = String.format("%tF%n", calendar)
The challenge here is that java.util.Calendar
is not supported in GWT client side, Is there a possible solution without having to move this code to server side ?
Thanks
com.google.gwt.user.datepicker.client.CalendarUtil
is what you are looking for, I guess;
Easiest would probably be to use Joda-time or similar, but all GWT ports of JodaTime have been abandonned: Date time library for gwt
The most performant (no third-party dependency) would be to do the calculation yourself:
Date d = new Date();
int dow = d.getDay();
int wed_delta = 3 - dow;
wed = new Date(d.getTime() + (86400 * wed_delta));
(the last line could be replaced with CalendarUtil.addDaysToDate(d, wed_delta)
, modifying d
in-place)
using DateTimeFormat
, it allows format a java.util.Date into string or format a string into Date.
Date date = new Date();
DateTimeFormat format = DateTimeFormat.getFormat("EEEE");
String day = format.parse(date);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With