java获取当前日期的前一天日期与字符串日期之间的转换
这几天一直在处理Java的日期问题,通常需要按要求生成日期的话,通常会用到util包中的Calendar类,再用Calendar的getTime()方法生成对应的Date,最后用SimpleDateFormat输出。
1. 获取当期日期、年份、月份
import java.util.Calendar;
public class Main {
public static void main(String[] args) {
Calendar now = Calendar.getInstance();
System.out.println("Current Year is : " + now.get(Calendar.YEAR));
// month start from 0 to 11
System.out.println("Current Month is : " + (now.get(Calendar.MONTH) + 1));
System.out.println("Current Date is : " + now.get(Calendar.DATE));
}
}
2. 获取前一天、前一个月的日期
Calendar calendar = Calendar.getInstance();//此时打印它获取的是系统当前时间
calendar.add(Calendar.DATE, -1); //得到前一天
String yestedayDate
= new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
calendar.add(Calendar.MONTH, -1); //得到前一个月
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH)+1; //输出前一月的时候要记得加1
3. 字符串转为日期格式
String date = "2010-02-01 23:59:59";
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
try {
Date d = sf.parse(date);
System.out.println(sf.format(d));
} catch (ParseException e) {
e.printStackTrace();
}
相关文档:
Java一定要掌握的技术
-------------------------------------------------------------------------------
jvm优化
jvm线程调度序列
java gc机制
java gc算法
Java gc原理
java 内存管理
如何主动通知jvm进程垃圾回收
异常机制|java的异常处理
线程|线程的实现
集合类框架
java.io
服务器:Squid、Lighttpd、 ......
在面向对象编程中,对于类,对象,方法,变量等方面的命名是非常有技巧的。比如,大小写的区分,使用不同
字母开头等等。但究其本,追其源,在为一个资源其名称的时候,应该本着描述性以及唯一性这两大特征来命名,才能保证资源之间不冲突,并且每一个都便于记
忆。
......
这里只能从显示数据的jsp页面上导出当前页面的数据,这些数据可以从数据库读出,显示到jsp页面,然后加一段话就可把当前页面数据保存到excel里面!
如从后台过来数据显示到 showUser.jsp
然后加链接到 showExcel.jsp就可以了,在这个页面只多了几行字,其他的都不会显示包括页面!但这个页面上的数据跟showUser.js ......
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体" ......
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体" ......