Java 格式化类

A.日期格式化

1、日期格式
DateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss.SSS ");

2、日期
Date date= new Date();
Date date= new Date(时间); ---时间是1970-1-1以后的毫秒数

3、日历
Calendar cal = Calendar.getInstance();
  cal.set(2015, 0, 31, 8, 20, 59);

  // 往下溢出--减去
  cal.add(Calendar.MONTH, 1);

  //往上进位
  cal.add(Calendar.DATE, 1);

  //获得日期
  Date date = cal.getTime();

 

B.数字格式化

new DecimalFormat("#.#####");  
0  数字,没有放零
#  数字,没有就没有
.  小数位置
,  整数位置的分割符

% 百分比

NumberFormat.getCurrencyInstance(); --货币格式化
NumberFormat.getIntegerInstance();   --整数格式化
NumberFormat.getNumberInstance();  --小数格式化
NumberFormat.getPercentInstance(); --百分比格式化

 

C.字符串格式化

MessageFormat.format

MessageFormatPattern:
         String
         MessageFormatPattern FormatElement String

 FormatElement:
         { ArgumentIndex }
         { ArgumentIndex , FormatType }
         { ArgumentIndex , FormatType , FormatStyle }

 FormatType: one of
         number date time choice

 FormatStyle:
         short
         medium
         long
         full
         integer
         currency
         percent
         SubformatPattern

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值