12

我正在开发一个 gwt 应用程序,该应用程序涉及对日期时间的高级操作:从一个时区转换为另一个时区等。Gwt 有一些用于处理日期的低级东西,但它们对我来说太低级了。有没有类似于 joda time 或 threeten for gwt 的选项?

4

2 回答 2

5

您可以查看以下选项。

http://code.google.com/p/gwt-time/

http://code.google.com/p/goda-time/

http://github.com/mping/gwt-joda-time

于 2012-04-25T09:26:54.743 回答
1

这是我的 DateTimeUtil 类

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;
    }
}
于 2014-12-08T22:31:46.173 回答