java 获取特定天数的时间戳
2024-10-10 19:16:12
public Timestamp strToDate(int type){
Timestamp time = null;
DateFormat format2= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
Calendar cale = Calendar.getInstance();
cale.add(Calendar.DATE, type);
String tarday = new SimpleDateFormat("yyyy-MM-dd").format(cale.getTime())+" 00:00:00"; // String转Date try {
date = format2.parse(tarday);
System.out.println(date.getTime());
time = new Timestamp(date.getTime());
System.out.println(time.toString());
} catch (ParseException e) {
e.printStackTrace();
} return time;
}
type 为-1 表示获取昨天的日期,-2为前天的日期,以此类推。0 为今天的日期。
最新文章
- Photoshop、Illustrator思维导图笔记
- ABP督导项目(1)
- INADDR_ANY
- yum install maven
- Winform开发框架的重要特性总结
- [jquery] jQuery jsTree V3.2.1 基础Demo
- Parse--Saving Images(翻译)
- spark1.1.0部署standalone分布式集群
- 自己定义flash的宽和高
- C陷阱与缺陷(二)
- JavaScript嗅探执行神器-sniffer.js,你值得拥有!
- Swift3.0 函数闭包与OC Block
- 201521123024《Java程序设计》第7周学习总结
- about:firefox set
- go 使用 c接口
- Lua语法基础(二)
- [数学笔记Mathematical Notes]2-一个带对数的积分不等式
- jieba(杰巴)分词的三种模式
- Cookie的几点忠告
- VirtualBox--虚拟机网络设置1--(四种方式)
热门文章
- 私有静态方法private static method-值得用吗?
- 剑指offer-面试题3.二维数组中的查找
- LeeCode-Remove Linked List Elements
- C:\Program Files (x86)\Common Files\microsoft shared\TextTemplating\11.0
- 【转】android camera(四):camera 驱动 GT2005
- ASP.NET中连接数据库的各种方法
- UVA10199- Tourist Guide(割点)
- 从决策树学习谈到贝叶斯分类算法、EM、HMM
- LR实战之Discuz开源论坛——登录脚本
- ThinkPHP使用Memcached缓存数据