繁体   English   中英

由于SimpleDateFormat [LIBGDX],GWT编译失败

[英]GWT compilation fails due to SimpleDateFormat [LIBGDX]

如您所知,GWT不支持SimpleDateFormat 但是到目前为止,我找不到任何替代方法。

public Player(String name, int score, Date dateScore){
    this.name = name;
    this.score = score;
    this.dateScore = dateScore;
    if(dateScore != null){
        this.dateScoreFormatted = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dateScore);
    }   
}

这个家伙在这里说要导入com.google.gwt.i18n.client.DateTimeFormat ,但是我不知道如何导入它。 Libgdx是否可以在本机 Android和桌面应用程序上使用?

GWT代码可编译为JavaScript。 它将在所有受支持的浏览器(包括移动和桌面浏览器)中运行。

是的,您需要使用com.google.gwt.i18n.client.DateTimeFormat

感谢@No谁为我澄清了一切。

如果其他人需要它,则可以使用ActionResolver并导入每个平台支持的正确类。 查看特定的代码实现

现在,对于HTML5版本来说,这就是它的工作方式:

public class HtmlLauncher extends GwtApplication implements com.yourpackage.util.ActionResolver{

    @Override
    public GwtApplicationConfiguration getConfig () {
            return new GwtApplicationConfiguration(360, 640);
    }

    @Override
    public ApplicationListener getApplicationListener () {
            return new MyGame(this);
    }

    @Override
    public String convertDate(String format, Date date) {
        DefaultDateTimeFormatInfo info = new DefaultDateTimeFormatInfo();
        DateTimeFormat dateFormat = new DateTimeFormat(format, info) {}; 

        return dateFormat.format(date);
    }

    @Override
    public Date parseDate(String format, String date) {
        DefaultDateTimeFormatInfo info = new DefaultDateTimeFormatInfo();
        DateTimeFormat dateFormat = new DateTimeFormat(format, info) {}; 

        return dateFormat.parse(date);
    }
}

对于Android和桌面ActionResolvers您可以正常使用SimpleDateFormat ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM