日期、格式化输出的写法
程序员文章站
2024-02-22 23:05:47
...
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Format {
public static void main(String[] args) {
String message = "{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}";
Object[] array = new Object[] {'A','B','C','D','E','F','G','H','I','J'};
//format(格式化格式,对象)
String value = MessageFormat.format(message, array);
System.out.println(value);
message = "{0,number,#.##} is a good number";
array = new Object[] {new Double(13.1415926)};
value = MessageFormat.format(message, array);
System.out.println(value);
//日期的格式化
String strDate = "2008-10-09 10:11:30.100";
String pat1 = "yyyy-MM-dd HH:mm:ss.SSS";
String pat2 = "yyyy年MM月dd日 HH时mm分ss秒SSS毫秒";
SimpleDateFormat dat1 = new SimpleDateFormat(pat1);
SimpleDateFormat dat2 = new SimpleDateFormat(pat2);
Date date = null;
try {
date = dat1.parse(strDate);
} catch (ParseException e) {
e.printStackTrace();
}
System.out.println(dat2.format(date));
}
}
上一篇: angular中格式化日期