功能更强大的格式化工具类 FormatUtils.java
- package com.util;
- import java.text.DecimalFormat;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- /**
- * 功能更强大的格式化工具类
- */
- public class FormatUtils {
- private static SimpleDateFormat second = new SimpleDateFormat(
- "yy-MM-dd hh:mm:ss");
- private static SimpleDateFormat day = new SimpleDateFormat("yyyy-MM-dd");
- private static SimpleDateFormat detailDay = new SimpleDateFormat("yyyy年MM月dd日");
- private static SimpleDateFormat fileName = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
- private static SimpleDateFormat tempTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- private static SimpleDateFormat excelDate = new SimpleDateFormat("yyyy/MM/dd");
- /**
- * 格式化excel中的时间
- * @param date
- * @return
- */
- public static String formatDateForExcelDate(Date date) {
- return excelDate.format(date);
- }
- /**
- * 将日期格式化作为文件名
- * @param date
- * @return
- */
- public static String formatDateForFileName(Date date) {
- return fileName.format(date);
- }
- /**
- * 格式化日期(精确到秒)
- *
- * @param date
- * @return
- */
- public static String formatDateSecond(Date date) {
- return second.format(date);
- }
- /**
- * 格式化日期(精确到秒)
- *
- * @param date
- * @return
- */
- public static String tempDateSecond(Date date) {
- return tempTime.format(date);
- }
- public static Date tempDateSecond(String str) {
- try {
- return tempTime.parse(str);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- return new Date();
- }
- /**
- * 格式化日期(精确到天)
- *
- * @param date
- * @return
- */
- public static String formatDateDay(Date date) {
- return day.format(date);
- }
- /**
- * 格式化日期(精确到天)
- *
- * @param date
- * @return
- */
- public static String formatDateDetailDay(Date date) {
- return detailDay.format(date);
- }
- /**
- * 将double类型的数字保留两位小数(四舍五入)
- *
- * @param number
- * @return
- */
- public static String formatNumber(double number) {
- DecimalFormat df = new DecimalFormat();
- df.applyPattern("#0.00");
- return df.format(number);
- }
- /**
- * 将字符串转换成日期
- *
- * @param date
- * @return
- * @throws Exception
- */
- public static Date formateDate(String date) throws Exception {
- return day.parse(date);
- }
- /**
- * 将字符日期转换成Date
- * @param date
- * @return
- * @throws Exception
- */
- public static Date parseStringToDate(String date) throws Exception {
- return day.parse(date);
- }
- public static String formatDoubleNumber(double number) {
- DecimalFormat df = new DecimalFormat("#");
- return df.format(number);
- }
- }
功能更强大的格式化工具类 FormatUtils.java的更多相关文章
- 发一个比trace功能更强大debug工具,MonterDebugger
经常看到兄弟说trace不出东西啊,这样给你调试会带来很多不便:加入说我们需要将运行时的debug信息和之前某个版本的进行比对:又加入说我们需要在运行时通过debug动态调整显示对象的属性:查看当前整 ...
- 让Docker功能更强大的10个开源工具
让Docker功能更强大的10个开源工具 更好的管理.Web前端程序.更深入地了解容器应用程序,Docker生态系统正在迅速发展,这还得归功于其充满活力的开源社区. 软件项目的成功常常根据其催生的生态 ...
- pandas的筛选功能,跟excel的筛选功能类似,但是功能更强大。
Select rows from a DataFrame based on values in a column -pandas 筛选 https://stackoverflow.com/questi ...
- 比 Navicat 还要好用、功能更强大的工具!
DBeaver 是一个基于 Java 开发,免费开源的通用数据库管理和开发工具,使用非常友好的 ASL 协议.可以通过官方网站或者 Github 进行下载. 由于 DBeaver 基于 Java 开发 ...
- 一个比 Nginx 功能更强大的 Web 服务器
公众号关注 「开源Linux」 回复「学习」,有我为您特别筛选的学习资料~ Caddy 简介 Caddy 是一个 Go 编写的 Web 服务器,类似于 Nginx,Caddy 提供了更加强大的功能,随 ...
- Excel Interactive View - 让页面表格的功能更强大
MS Office Excel Services提供了一个非常强大的功能,允许你只需要在页面上添加非常少量的JS references,就可以让你在页面上将表格的内容以Excel图表的方式呈现.这里是 ...
- 让ecshop编辑器功能更强大
ecshop后台的商品编辑和文章编辑使用的是FCKEDITOR 编辑器, 这个FCKEDITOR的工具条(toolbar)是可以自定义的,ECSHOP默认使用的是 normal ,属于中档功能, 下面 ...
- C++ folly库解读(三)Synchronized —— 比std::lock_guard/std::unique_lock更易用、功能更强大的同步机制
目录 传统同步方案的缺点 folly/Synchronized.h 简单使用 Synchronized的模板参数 withLock()/withRLock()/withWLock() -- 更易用的加 ...
- 更强大的trim功能,过滤汉字等
第一种方法:通过php自带的函数 <?php /* trim 去除一个字符串两端空格, rtrim 是去除一个字符串右部空格, ltrim 是去除一个字符串左部空格. */ ?> < ...
随机推荐
- C#_控件——DropDownList
1.html <asp:CheckBox ID="CheckBox11" runat="server" onclick="changecheck ...
- 第二个Sprint冲刺第四天
讨论地点:宿舍 讨论成员:邵家文.李新.朱浩龙.陈俊金 今天的发展,探讨了统计功能的问题: 一.统计数据针对的是什么功能? 1.初衷是针对计时的填空题,至于其它功能统不统计,那要看开发的进度. 二.对 ...
- ERROR 1130: Host ’...′ is not allowed to connect to this MySQL server
/******************************************************************** * ERROR 1130: Host ’...′ is no ...
- python模块的安装
1.下载所需模块 2.解压到一个目录 3.window下打开cmd 4.切换到模块setup.py目录 5.执行python setup.py install安装 前提是安装了python,并且配置了 ...
- 利用HTML5云存储实现模拟对比投票效果
<!DOCTYPE HTML> <html> <head> <title>模拟对比投票效果</title> <meta name=&q ...
- css中常用的hack
<!DOCTYPE html> <html> <head> <title>Css Hack</title> <style> #t ...
- 334. Increasing Triplet Subsequence
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...
- Codeforces Round #144 (Div. 2)
A. Perfect Permutation 奇偶对调. B. Non-square Equation \(s(x)\)不超过200,根据求根公式计算\(x\). C. Cycles 每次新增点时都和 ...
- 那些盒模型在IE6中的BUG们,工程狮的你可曾遇到过?
HTML5学堂 那些盒模型在IE6中的BUG们,工程狮的你可曾遇到过? IE6已经渐渐的开始退出浏览器的历史舞台.虽然当年IE6作为微软的一款利器击败网景,但之后也因为版本的持续不更新而被火狐和谷歌三 ...
- Linux系统编程@多线程编程(二)
线程的操作 线程标识 线程的ID表示数据类型:pthread_t (内核中的实现是unsigned long/unsigned int/指向pthread结构的指针(不可移植)几种类型) 1.对两个线 ...