0

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.

Eliran Malka
  • 15,821
  • 6
  • 77
  • 100
sumit
  • 55
  • 5
  • 10
  • 2
    possible duplicate of [How to do calendar operations in Java GWT? How to add days to a Date?](http://stackoverflow.com/questions/2527845/how-to-do-calendar-operations-in-java-gwt-how-to-add-days-to-a-date) – Thomas Broyer Apr 12 '12 at 11:08

3 Answers3

0

Calendar is not part of GWT JRE emulation. You can refer older posts which have answer for your question. Here is the link

Community
  • 1
  • 1
Ganesh Kumar
  • 3,220
  • 1
  • 19
  • 27
0

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;
    }
}
teteArg
  • 3,684
  • 2
  • 20
  • 18
0

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.

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
foal
  • 693
  • 7
  • 20