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