首页 > 编程语言 > 详细

如何利用java得到当前的时间和前一天的时间

时间:2016-07-04 22:05:54      阅读:239      评论:0      收藏:0      [点我收藏+]

1.得到当前的时间 

Ruby代码  技术分享
  1. Calendar   cal   =   Calendar.getInstance();   
  2. String time=formatter.format(cal.getTime());  
  3. String strEnd=time.substring(0, 16);// 2007-10-30 09:30  


2.得到前一天的时间 

Ruby代码  技术分享
  1. Calendar   c   =   Calendar.getInstance();   
  2. c.add(Calendar.DAY_OF_MONTH, -1);  
  3. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
  4. String mDateTime=formatter.format(c.getTime());  
  5. String strStart=mDateTime.substring(0, 16);//2007-10-29 09:30  


3.得到前几天的时间 

Ruby代码  技术分享
  1. Calendar   c   =   Calendar.getInstance();   
  2. c.add(Calendar.DAY_OF_MONTH, -5);//得到前5  
  3. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
  4. String mDateTime=formatter.format(c.getTime());  
  5. String strStart=mDateTime.substring(0, 16);//2007-10-24 09:30  


4.得到当前时间的前几年的时间 

Ruby代码  技术分享
    1. Calendar   c   =   Calendar.getInstance();   
    2.   c.add(Calendar.YEAR, -5);//得到前5年  
    3.   SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
    4.   String mDateTime=formatter.format(c.getTime());  
    5.   String strStart=mDateTime.substring(0, 16);//2002-10-24 09:30  

来自:http://heiwuya.iteye.com/blog/294174

如何利用java得到当前的时间和前一天的时间

原文:http://www.cnblogs.com/lanliying/p/5641638.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!