时间格式化

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. uvalive 3602 DNA Consensus String

    https://vjudge.net/problem/UVALive-3602 题意: 给定m个长度均为n的DNA序列,求一个DNA序列,使得它到所有的DNA序列的汉明距离最短,若有多个解则输出字典序 ...

  2. 【Jhipster】升级/修改 数据库结构

    前提 1.jhipster环境,jdk1.8,yeoman,node.js安装环境参考官方wiki,环境问题参考我的博客,如果出现注册中心空白页,请参考博客 2.首先需要启动jhipster基础服务, ...

  3. vue-router详解——小白速会

    一.概述 vue-router是Vue.js官方的路由插件,它和vue.js是深度集成的,适合用于构建单页面应用. vue的单页面应用是基于路由和组件的,路由用于设定访问路径,并将路径和组件映射起来. ...

  4. 【贪心】Codeforces 349B.Color the Fence题解

    题目链接:http://codeforces.com/problemset/problem/349/B 题目大意 小明要从9个数字(1,2,--,9)去除一些数字拼接成一个数字,是的这个数字最大. 但 ...

  5. Linux(二)CentOS的安装

    centos6.8 链接:https://pan.baidu.com/s/1TjCYXzijMzfpiZ9Z-D1Qhg 密码:7mvn 2.1 新建虚拟机 1 2.2 选中稍后安装操作系统(先把虚拟 ...

  6. 1086: [SCOI2005]王室联邦

    1086: [SCOI2005]王室联邦 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 1554  Solved: ...

  7. [HNOI 2015]接水果

    Description 风见幽香非常喜欢玩一个叫做 osu!的游戏,其中她最喜欢玩的模式就是接水果. 由于她已经DT FC 了The big black,  她觉得这个游戏太简单了,于是发明了一个更 ...

  8. [USACO12JAN]爬山Mountain Climbing

    题目描述 Farmer John has discovered that his cows produce higher quality milk when they are subject to s ...

  9. ●BZOJ 2006 NOI 2010 超级钢琴

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2006 题解: RMQ + 优先队列 (+ 前缀) 记得在一两个月前,一次考试考了这个题目的简 ...

  10. 2017ACM/ICPC广西邀请赛-重现赛 1010.Query on A Tree

    Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey A learne ...