java数字格式化, 时间换算工具方法
来源:互联网 发布:淘宝星期一 编辑:程序博客网 时间:2024/06/05 18:28
java数字格式化, 时间换算工具方法
Java格式化数字——右对齐,左补0
方法一
DecimialFormat format = new DecimialFormat("00");int number = 9;System.out.println(format.format(number)); // 应该输出 09
方法二
String str2 = String.format("%04d", number2);
时间差换算成字符串方法
最开始没有考虑到integer的大小范围,出现了没法判断到周的情况,这个方法解决了这个问题
/** * 计算两个日期型的时间相差多少时间 * * @return */ public static String getTimeDiff(Date postDate) { Date currentDate = new Date(); if (postDate == null || currentDate == null) { return null; } long timeLong = currentDate.getTime() - postDate.getTime(); long secondScope = 60*1000; long minuteScope = secondScope*60; long hourScope = minuteScope*24; long dayScope = hourScope*7; long weekScope = dayScope*4; long monthScope = weekScope*12; if (timeLong < secondScope) // 小于60秒 return timeLong / 1000 + "秒前"; else if (timeLong < minuteScope) { // 小于60分钟 timeLong = timeLong / secondScope; return timeLong + "分钟前"; } else if (timeLong < hourScope) { // 小于24小时 timeLong = timeLong / minuteScope; return timeLong + "小时前"; } else if (timeLong < dayScope) { // 小于7天 timeLong = timeLong / hourScope; return timeLong + "天前"; } else if (timeLong < weekScope) { // 小于4周 timeLong = timeLong / dayScope; return timeLong + "周前"; } else if(timeLong < monthScope){ timeLong = timeLong / weekScope; return timeLong + "月前"; } else { SimpleDateFormat sdf = new SimpleDateFormat(Constant.DATE_PATTERN2); return sdf.format(postDate); } }
0 0
- java数字格式化, 时间换算工具方法
- 数字、时间等单位换算工具类收集
- java经纬度换算距离,date换算字符串工具方法
- JAVA 数字格式化处理方法
- [JAVA] 数字格式化显示方法
- 时间换算(java)
- Java 时间换算
- Java数字日期时间格式化处理
- Java格式化日期、时间、数字、字符串
- js格式化日期时间的工具方法
- javascript格式化时间的工具方法
- Java技术时间格式化处理工具类
- JAVA 数字格式化处理方法; 国际化
- java 格式化输出数字的方法
- java 格式化输出数字的方法
- java格式化输出数字的方法
- java中格式化输出数字的方法
- 时间格式化,时间戳生成等工具方法
- java并发编程实战手册(一)线程管理
- 问题解决:Unlink of file '.git/objects/pack/pack-***.pack' failed. Should I try again? (y/n) y
- HDOJ 2199 Can you solve this equation?(二分查找)
- ETag/If-None-Match
- Object对象详解(二)之clone
- java数字格式化, 时间换算工具方法
- 【数论】快速幂及取余wikioi1497,2952
- MyEclipse图表工具Birt的使用技巧(三)--连接webservice数据源
- 文件处理——输出文件到屏幕显示
- ajax跨域问题解决方法
- ETag/If-None-Match
- Leetcode39 Combination Sum
- loser跟专业无关
- 学习心得