Custom Date tag: custom date based on pattern format. Default date is current day.
  <CUSTOMDATE[+,-][value][scale],Pattern>
  User can define the date format by customize the parameter Pattern.
  Scale is only recognized within below option:
    “Y” for year, “M” for month, “D” for day
Sample:
  Suppose today is 16 Dec 2014
    <CUSTOMDATE+1M,MMM yyyy> return as “Jan 2015”
    <CUSTOMDATE-1D,ddMMyyyy> return as “15122015”
    <CUSTOMDATE-2Y,dd*MMMMyyyy> return as “16*December2012”

   /**
* @param input
* <CUSTOMDATE[+,-][number][scale],Pattern>
* @return custom date based on pattern format. default date is current day
*/
private String customDate(String input) {
input = input.substring(1, input.length() - 1);
String pattern = input.split(",")[1].trim();
input = input.split(",")[0].trim();
Date now = new Date();
SimpleDateFormat ft = new SimpleDateFormat(pattern);
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(now);
int len = "CUSTOMDATE".length();
if (input.length() == len) {
return ft.format(now);
} else if (input.length() < len) {
return "The format you input is incorrect! Please make sure the format is <CUSTOMDATE[+,-][number][scale],Pattern>";
} else {
String math = input.substring(len, len + 1);
int value = Integer.parseInt(input.substring(len + 1,
input.length() - 1));
String scale = input.substring(input.length() - 1);
if (math.equals("-")) {
value = -value;
} else if (!math.equals("+")) {
return "Math is wrong. Can only use +/-.";
}
int field = 0;
if (scale.equalsIgnoreCase("Y")) {
field = 1;
} else if (scale.equalsIgnoreCase("M")) {
field = 2;
} else if (scale.equalsIgnoreCase("D")) {
field = 5;
}
if (field == 0) {
return "The scale is wrong. Can only use Y/M/D.";
}
gc.add(field, value);
}
return ft.format(gc.getTime());
}

Custom Date tag的更多相关文章

  1. Tag file

    JSP 2.0 引入 Tag file ,tag file 以 tag 或 tagx 为后缀,它们可以包含其他资源文件:一个被其他文件包含的 tag file 应该以 tagf 为后缀. 如同JSP页 ...

  2. HTML Custom Elements (v1)

    HTML Custom Elements (v1) https://developers.google.com/web/fundamentals/web-components/customelemen ...

  3. snakeyaml - Documentation.wiki

    SnakeYAML Documentation This documentation is very brief and incomplete. Feel free to fix or improve ...

  4. Mybatis Generator生成数据库自带的中文注释

    1.相关jar包 <!-- mybatis生成 jar包 --> <dependency> <groupId>org.mybatis.generator</g ...

  5. 关于 mybatis-generator自定义注释生成 使用DefaultCommentGenerator重写来完成

    项目里新建表时model,mapper以及mapper.xml基本都是用Mybatis Generator(以下简称为MBG)自动生成的,但是MBG自动生成的model的注释实在有点非人类,至少中国人 ...

  6. Mybatis Generator的model生成中文注释,支持oracle和mysql(通过实现CommentGenerator接口的方法来实现)

    自己手动实现的前提,对maven项目有基本的了解,在本地成功搭建了maven环境,可以参考我之前的文章:maven环境搭建 项目里新建表时model,mapper以及mapper.xml基本都是用My ...

  7. vue源码逐行注释分析+40多m的vue源码程序流程图思维导图 (diff部分待后续更新)

    vue源码业余时间差不多看了一年,以前在网上找帖子,发现很多帖子很零散,都是一部分一部分说,断章的很多,所以自己下定决定一行行看,经过自己坚持与努力,现在基本看完了,差ddf那部分,因为考虑到自己要换 ...

  8. mybatis根据数据库表结构自动生成实体类,dao,mapper

    首先, pom需要引入 <!-- mysql --> <dependency> <groupId>mysql</groupId> <artifac ...

  9. 腾讯发布新版前端组件框架 Omi,全面拥抱 Web Components

    Omi - 合一 下一代 Web 框架,去万物糟粕,合精华为一 → https://github.com/Tencent/omi 特性 4KB 的代码尺寸,比小更小 顺势而为,顺从浏览器的发展和 AP ...

随机推荐

  1. erlang反编译

    Beam = code:which(MyModuleName). {ok,{_,[{abstract_code,{_,AC}}]}} = beam_lib:chunks(Beam,[abstract_ ...

  2. python学习-day11-内建函数

    python-内建函数 -int:将字符串转换为数字 a = " print(type(a),a) b = int(a) print(type(b),b) num = " v = ...

  3. 报错:java.lang.IllegalStateException: Cannot call sendError() after the response has been committed(待解答)

    严重: Servlet.service() for servlet [default] in context with path [/20161101-struts2-1] threw excepti ...

  4. C#使用ConditionalAttribute特性来实现代码调试

    转自:http://www.csharpwin.com/csharpspace/10729r8541.shtml #if/#endif条件编译常用来由同一份源代码生成不同的结果文件,最常见的有debu ...

  5. PLSQL_性能优化工具系列02_SQL Tuning Health-Check Script (SQLHC)

    2014-08-23 Created By BaoXinjian

  6. HTML5 编辑 API 之 Range 对象(一)

     一.Range 对象基本概念 通过使用 Range 对象所提供的方法实现一个鼠标选取内容,通过点击按钮打印出选中内容,当然注意在不同的浏览器下可选中的内容数量是不同的. <!DOCTYPE h ...

  7. java 子接口中定义与父接口相同的方法

    今天碰到一个很有意思的问题,在java中如果子接口中定义了与父接口中已经有的方法会发生什么事情呢?比如: interface IRunnable extends Runnable{ void run( ...

  8. JAVA变量的类型,定义变量

    JAVA中常用的数据类型 数据类型 数据类型解释 说明 char 字符型 用于存储单个字符,如:性别“男”.“女”,电灯“开”.“关” int 整形 用于存储整数,如一天的时间是24小时,一月份是31 ...

  9. laravel判断HTTP请求是否ajax

    if(Request->ajax()){ echo "AJAX"; }else{ echo '普通请求':}

  10. 并发容器之ConcurrentSkipListSet

    概要 本章对Java.util.concurrent包中的ConcurrentSkipListSet类进行详细的介绍.内容包括:ConcurrentSkipListSet介绍ConcurrentSki ...