java的几个format
public static String formatDateToString(long date) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssSSS");
return formatter.format(date);
}
public String formatDate(Date date){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
return formatter.format(date);
}
//时间戳的格式化,当前时间往前推7天的时间戳:new Date().getTime()-7*24*3600*1000;
public String formatDate(long date){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
return formatter.format(date);
}
public long formatDate(String date){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date d = null;
try {
d = formatter.parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
return d.getTime();
}
//相除的两个数,在JAVA中,应该用double类型的,保留两位小数点
public double decimalFormat(double f){
DecimalFormat decimalFormat=new DecimalFormat(".00");
return Double.valueOf(decimalFormat.format(f));
}
public double decimalFormat(long a, long b){
DecimalFormat decimalFormat=new DecimalFormat(".00");
return Double.valueOf(decimalFormat.format((double)a/b));
}
java的几个format的更多相关文章
- JAVA字符串格式化String.format()的使用
JAVA字符串格式化-String.format()的使用常规类型的格式化 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语言的sprin ...
- java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
此方法为Timestamp的 转换方法. 这几天做到excel导入功能,其中里面有几个时间时段,所以用了这个类来将导入的字符串格式转换Timestamp格式. 不慎出现了 java.lang.Ille ...
- java日期格式大全 format SimpleDateFormat(转)
java日期格式大全 format SimpleDateFormat /** * 字符串转换为java.util.Date<br> * 支持格式为 yyyy.MM.dd G ...
- JAVA字符串格式化-String.format()的使用 【生成随机数补0操作】
转: JAVA字符串格式化-String.format()的使用 常规类型的格式化 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语言的s ...
- Java中强大的format
Java中强大的format Java中允许我们对指定的对象进行某种格式化,从而得到我们想要的格式化样式. Format 首先介绍java.text包中的Format Foramt是一个抽象基类,其具 ...
- Java系列: JAVA字符串格式化-String.format()的使用(zz)
常规类型的格式化 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语言的sprintf()方法,两者有类似之处.format()方法有两种重 ...
- java中的String.format使用
format(String format, Objece... argues)函数相当于C语言中的printf函数,但是相对来说更灵活. 和C中的printf函数差不多,在fo ...
- Java 8 – How to format LocalDateTime
Few examples to show you how to format java.time.LocalDateTime in Java 8. 1. LocalDateTime + DateTim ...
- java.lang.IllegalArgumentException: Cannot format given Object as a Date
在进行日期转换的时候遇到了这个问题, 非常的恼火 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" ...
随机推荐
- Graph 卷积神经网络:概述、样例及最新进展
http://www.52ml.net/20031.html [新智元导读]Graph Convolutional Network(GCN)是直接作用于图的卷积神经网络,GCN 允许对结构化数据进行端 ...
- 从VMware虚拟机安装到hadoop集群环境配置详细说明(第一期)
http://blog.csdn.net/whaoxysh/article/details/17755555 虚拟机安装 我安装的虚拟机版本是VMware Workstation 8.04,自己电脑上 ...
- OpenGL ES Shader语言中的函数不支持递归
An example function definition is given here for a simple function that computes basic diffuse light ...
- template.helper 多参数
<script type="text/html" id="text4"> {{detail name classInfo schoolInfo}} ...
- HTTP协议综合
1.用浏览器模拟各种User Agent 测试页面的时候经常需要不同的User Agent,Firefox.Chrome浏览器就可以完美的模拟出各种User Agent.User Agent Swit ...
- 【转】Java抽象类与接口的区别
很多常见的面试题都会出诸如抽象类和接口有什么区别,什么情况下会使用抽象类和什么情况你会使用接口这样的问题.本文我们将仔细讨论这些话题. 在讨论它们之间的不同点之前,我们先看看抽象类.接口各自的特性. ...
- WPF按钮删除默认的鼠标悬停效果
<Style x:Key="NormalMouseButton" TargetType="Button"> <Setter Property= ...
- LintCode: 3 Sum
C++ 把3个数求和,转变为2个数求和 1. 把数组排序 2. 注意过滤重复值 3. 从前到后遍历,游标i 4. 从后边数中找start + end = -arr[i]的2 sum 5. start ...
- Ant详解之-path、classpath和fileset
转自:http://www.cnblogs.com/itech/archive/2011/11/01/2231206.html 一 .<path/> 和 <classpath/> ...
- nginx获得response自定义的header
Response header send by upstream is $upstream_http_x_uuid http://wiki.nginx.org/HttpUpstreamModule#. ...