Spring Java @DateTimeFormat [英] Spring Java @DateTimeFormat

查看:362
本文介绍了Spring Java @DateTimeFormat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个助手来解析Web服务中的时间,并使用@DateTimeFormat以另一种格式
输出。但是,在我的jsp视图中,此格式未格式化。我使用的是这个错误吗?

I have created a helper to parse time froma webservice and output inanother format using @DateTimeFormat. However in my jsp view this is not formatted. Am I using this wrong?

 @Component
public class DateParserHelper {

    @DateTimeFormat(style="F-")
    public Date getFormattedDate() {
        return formattedDate;
    }


    public void setFormattedDate(Date formattedDate) {

        this.formattedDate = formattedDate;
    }


    public Date formattedDate;

    public void setDate(String date) throws ParseException {

        DateFormatter dateFormatter = new DateFormatter("y-M-d");
        setFormattedDate( dateFormatter.parse(date, UK));

    }





}


推荐答案

如果在jsp中使用JSTL,则可以使用formatDate格式化日期:

If you are using JSTL in your jsp, you could use formatDate to format your date :

<fmt:formatDate value="${yourDate}" pattern="dd/MM/yyyy" />

这篇关于Spring Java @DateTimeFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆