java.text.format

oh ,now it's time to sum up the class of "java.text.format" , as i forget how to format a date after using other's tools .

1、数字格式化   DecimalFormat

使用 java.text.format  decimalFormat = new DecimalFormat("#.##"); 保留2位小数,允许整数与小数不存在。

使用 java.text.format decimalFormat = new DecimalFormat("0.0#");保留2位小数,无小数,小数位补0 。 无整数,整数位补0


2、日起格式化   simpleDateFormat

使用java.text.format dateFormat = new SimpleDateFormat(pattern) .

pattern : yyyy-MM-dd HH:mm:ss SSS E 表示 2014-12-06 23:59:58 333 星期四  and then ,you can short of the pattern just to suit yourself

注意 : 使用mysql格式化日起保存到数据库的时候,请不要用毫秒,否则会四舍五入,  2014-12-06 23:59:58 500 会保存为 2014-12-07 00:00:00


3、文本替换格式化 MessageFormat

描述:使用一个数组中的元素去替换String(模板)中{ArgumentIndex , FormatType , FormatStyle}中的指定位置

{ArgumentIndex , FormatType , FormatStyle} : {数组下标,格式化数组类型,格式}

例如 : String message = "xiao ming is {0} {1,number,#.##}" , Object  array = new Object[]{"high",3.33333} , String value = MessageFormat.format(message,array);

结果 : xiao ming is high 3.33 .   message就是模板。

then just thinking the result   if the message is "xiao ming is {} " . 是会全部打出呢 还是 说取消大括号 ?

建议使用:new MessageFormat(message).format(array);  因为上面的代码我无法得出正确结论 ,同时下面的代码就是上面代码的解析。。


for more message , just view  http://www.xuebuyuan.com/1576172.html 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值