WebWork/struts2中格式化輸出數字和日期的方法

來源:互聯網
上載者:User

truts2的匹配模式詳情請見

http://java.sun.com/docs/books/tutorial/i18n/format/decimalFormat.html

 

可以在資源檔中定義日期及其數位格式化,例如在classpath下建立一個.properties檔案,起名為format.properties,內容如下
format.date = {0,date,dd-MM-yyyy}

{}裡面的意思如下
{ 參數序號(從0開始), 格式類形(number | date | time | choice),
格式樣式(詳情請見http://java.sun.com/docs/books/tutorial/i18n/format
/decimalFormat.html#numberpattern)}

用<s:text>進行引用

            
<
s:i18n 
name
="format"
>

                
<
s:text 
name
="format.date"
 
>

                    
<
s:param 
value
="user.birthday"
></
s:param
>
    
                
</
s:text
>

            
</
s:i18n
>

後台如果設定user.setBirthday(new Date());

前台顯示:09-04-2009

在屬性檔案中可以進行數字等格式話
format.percent = {0,number,##0.00'%'}
format.money = {0,number,$##0.00}

參見文章如下:
http://www.blogjava.net/keweibo/articles/174997.html

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.