FormatUtils java格式化 随笔
来源:互联网 发布:arm7的寄存器数据宽度 编辑:程序博客网 时间:2024/05/29 10:02
import java.text.DecimalFormat;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;public class FormatUtils {public static Date stringToDate(String str) {SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");Date date = null;try {date = sdf.parse(str);} catch (ParseException e) {e.printStackTrace();}return date;}/** * 将yyyy-MM-dd时间改为yyyy年MM月dd日 * @param date yyyy-MM-dd格式的时间 * @return */ public static String getDateWithNYRFormaterByLine(String date){ String newDateDisplay = date; Date newDate = FormatUtils.stringToDate(date); if (newDate != null){ SimpleDateFormat newSimpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日"); newDateDisplay = newSimpleDateFormat.format(newDate); } return newDateDisplay; }/*** 格式化钱** @param num* @return #,###,##0.00*/public static String formatMoney(Double num) {if (null == num) {return "0.00";}num = Double.valueOf(Math.round(num * 100)) / 100;DecimalFormat Formatter = new DecimalFormat("#,###,##0.00");return Formatter.format(num);}/** * 格式化日期 */ public static String formatDateTime(Date date) { if (null == date) return ""; SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); simpleDateFormat.setLenient(false); return simpleDateFormat.format(date); }/** * 格式化日期 */ public static String formatDate(Date date) { if (null == date) return ""; SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); simpleDateFormat.setLenient(false); return simpleDateFormat.format(date); } public static String formatYearMonth(Date date) { if (null == date) return ""; SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM"); simpleDateFormat.setLenient(false); return simpleDateFormat.format(date); } public static String formatYearMonthWithChinese(Date date) { if (null == date) return ""; SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月"); simpleDateFormat.setLenient(false); return simpleDateFormat.format(date); } public static Date praseStringToDate(String dateString) {SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");try {return sdf.parse(dateString);} catch (Exception e) {e.printStackTrace();return null;}}}
0 0
- FormatUtils java格式化 随笔
- formatutils.js
- ios--NSDate格式化(随笔)
- java 随笔
- java随笔
- java随笔
- JAVA随笔
- Java随笔
- java 随笔
- JAVA随笔
- java 随笔
- Java随笔
- java随笔
- java随笔
- java随笔
- java随笔
- Java 随笔
- java随笔
- Chapter 2. MATLAB数据及其运算
- AWD Format: About
- hibernate 的Configuration类
- Ruby on Rails学习笔记1
- 使用VS2012 的15个技巧
- FormatUtils java格式化 随笔
- 动态创建菜单时出错 afxwin1.inl 1023
- linux下创建oracle表空间(
- Asp.NET随记---NO1---Page类。
- 5.10.4 静态代码块
- 织梦高级搜索的一些小问题
- 【转载】winForm窗体关闭按钮 实现提示选择,托盘后台运行或退出(类似QQ托盘区运行)
- 编年体纪事
- ArcEngine发布WebService服务