一些常用格式化。价格、日期等 持续更新

1. 价格的格式化,三位带个逗号。注意DecimalFormat 类下的format方法需要接受一个数字类型,folat或者double,所以price需要强转一下。然后该方法返回string。

否则会报错,Cannot format given Object as a Number错误

DecimalFormat df = new DecimalFormat("#,###.00");
String formatPrice = df.format(Double.valueOf(price));

2.日期的格式化。系统时间或者毫秒数转日期。日期格式可以自定义

SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd"); 

processDate.format(new Date());
SimpleDateFormat messageDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
posted @ 2020-08-13 10:40  了悟  阅读(228)  评论(0编辑  收藏  举报