I need to get the date and time from a user and add it to the current date and time.
e.g. if current date is February 1st and time is 12:00pm, and the user input specifies 31 days and 2 hours - the output should be March 3rd, 02:00pm.
I need to get the date and time from a user and add it to the current date and time.
e.g. if current date is February 1st and time is 12:00pm, and the user input specifies 31 days and 2 hours - the output should be March 3rd, 02:00pm.
Calendar is not part of GWT JRE emulation. You can refer older posts which have answer for your question. Here is the link
This is my DateTimeUtil, you can use it.
public class DateTimeUtil {
public static String getYear(Date date) {
return DateTimeFormat.getFormat("yyyy").format(date);
}
public static String getMonth(Date date) {
return DateTimeFormat.getFormat("MM").format(date);
}
public static String getDay(Date date) {
return DateTimeFormat.getFormat("dd").format(date);
}
public static String getHour(Date date) {
return DateTimeFormat.getFormat("HH").format(date);
}
public static String getMinute(Date date) {
return DateTimeFormat.getFormat("mm").format(date);
}
public static String getSecond(Date date) {
return DateTimeFormat.getFormat("ss").format(date);
}
// The String year must to have yyyy format
public static Date getDate(String years, String months, String days, String hours, String minutes, String seconds) {
DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");
Date date = dtf.parse(years + "-" + months + "-" + days + " " + hours + ":" + minutes + ":" + seconds);
GWT.log("date parsed " + date);
return date;
}
}
You can use the https://github.com/foal/gwt-time. The library provides emulation of java.time
from Java 8. It supports 99,9% functionality of the original Java package.