时间格式化

public static String DEFAULT_FORMATDATE = "yyyy-MM-dd";

1.n天前的日期

/**
* luyanlong
* 默认查询前几天的数据
*/
public void formatTimeDay(int duringTime){
Calendar calendar=Calendar.getInstance();
String start=StringUtils.EMPTY;
String end=StringUtils.EMPTY;
try {
end=CCalendar.dateFormatString(DEFAULT_FORMATDATE, calendar.getTime());
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - duringTime);
start = CCalendar.dateFormatString(DEFAULT_FORMATDATE, calendar.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
this.setAttr("startTime",start);
this.setAttr("endTime",end);
}

2.n月前的时间

/**
* luyanlong
* 默认查询前几月的数据
*/
public void formatTimeMonth(int duringMonth){
Calendar calendar=Calendar.getInstance();
String start=StringUtils.EMPTY;
String end=StringUtils.EMPTY;
try {
end=CCalendar.dateFormatString(DEFAULT_FORMATDATE, calendar.getTime()); calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - duringMonth);
start = CCalendar.dateFormatString(DEFAULT_FORMATDATE, calendar.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
this.setAttr("startTime",start);
this.setAttr("endTime",end);
}

Java 求n天前的时间或者n月前的时间的更多相关文章

  1. Oracle获取一周前,一个月前,一年前, 本周,本月,当年的日期

    1.获取当前时间一周前的日期 ' day from dual 类似的 --当前时间减去7分钟的时间 ' MINUTE from dual --当前时间减去7小时的时间 ' hour from dual ...

  2. [转]Java中一周前一个月前时间计算方法

    Java中一周前一个月前时间计算方法 在java语言中,用如下方法获取系统时间: Date date = new Date(); String year=new SimpleDateFormat(&q ...

  3. Java求素数时出现错误

    Java求素数时出现错误 1.具体错误如下 No enclosing instance of type Prime is accessible. Must qualify the allocation ...

  4. 使用java的Calendar工具类获取到本月的第一天起始时间和最后一天结束时间。

    1.使用java的Calendar工具类获取到本月的第一天起始时间和最后一天结束时间. package com.fline.aic.utils; import java.text.DateFormat ...

  5. Java求字符串中出现次数最多的字符

    Java求字符串中出现次数最多的字符  [尊重原创,转载请注明出处]http://blog.csdn.net/guyuealian/article/details/51933611      Java ...

  6. Javascript实现时间转换为多少天前

    //实现时间转换,这篇文章发布时间为 2016/1/20 19:59:30 文章发表时间戳为:1453291170000于:11月前function getDateDiff(dateTimeStamp ...

  7. JavaScript时间处理之几个月前或几个月后的指定日期

    在平常项目开发过程中,经常会遇到需要在JavaScript中处理时间的情况,无非两种(1,逻辑处理  2,格式转换处理).当然要说相关技术博,园子里闭着眼睛都能抓一把,但是我要做的是:既然有幸被我碰到 ...

  8. 将时间转换为xxx天前 xxx..前

    <?php echo (time_fitle('2016-08-17 17:00:00')); function time_fitle($date){ date_default_timezone ...

  9. [python实用代码片段]python获取当前时间的前一天,前一周,前一个月

    python获取当前时间的前一天,前一周,前一个月. 实用python的datetime.timedelta方法,避免了有的月份是30和31等不同的情况. 获取前一个月的时间,方法实现:首先datet ...

随机推荐

  1. 基于DFS的拓扑排序

    传送门:Kahn算法拓扑排序 摘录一段维基百科上的伪码: L ← Empty list that will contain the sorted nodes S ← Set of all nodes ...

  2. .Net中Web增加加密狗管理

    由于业务中最近需要使用到加密狗,增加对Web代码的管控,所以需要进行加密狗使用的研究 首先,对于没有接触使用过加密狗的人需要有个大致的认识,加密狗分为 MasterDog, 1.下载加密狗的开发套件, ...

  3. [LeetCode] Valid Triangle Number 合法的三角形个数

    Given an array consists of non-negative integers, your task is to count the number of triplets chose ...

  4. Cmder Windows 下的终端神器

    废话 Windows 下常用的终端有两个,古老的 cmd 和功能强大但你记不住函数的 PowerShell ,两者我都用过一段时间,给我的提体验是功能够用,界面丑陋,虽然 win10 下可以通过调整背 ...

  5. ios开发-指纹识别

    最近我们使用支付宝怎么软件的时候,发现可以使用指纹了,看起来是否的高大上.当时苹果推出了相关接口,让程序写起来很简单哈. 在iPhone5s的时候,苹果推出了指纹解锁.但是在ios8.0的时候苹果才推 ...

  6. python day one 变量,if

    一.变量,常量 变量:用于储存和标记信息在内存中,方便日后被调用.操作和修改 常量:固定不变大的量.字母大写 命名规则: 1.由字母数字下划线组成,命名要有意义,区分大小写. 2.命名建议用下划线分割 ...

  7. Linux使用踩坑记

    Ubuntu安装坑: 1.对于新手第一次安装ubuntu,特殊情况会出现因为分辨率问题导致安装界面不全,无法进行下一步操作. 解决方案:使用alt+鼠标左键拖动屏幕Linux文件名乱码问题: 2.因为 ...

  8. [JLOI 2011]飞行路线&[USACO 09FEB]Revamping Trails

    Description Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并 ...

  9. [JSOI2007]合金

    Description 某公司加工一种由铁.铝.锡组成的合金.他们的工作很简单.首先进口一些铁铝锡合金原材料,不同种类的 原材料中铁铝锡的比重不同.然后,将每种原材料取出一定量,经过融解.混合,得到新 ...

  10. codeforces 815C Karen and Supermarket

    On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a ...