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. 使用NSOperation使用,创建线程中传递多个参数

    参考:http://blog.csdn.net/dqjyong/article/details/7677557 参考:http://stackoverflow.com/questions/232761 ...

  2. for语句的用法

    #!/bin/bashfor i in 1 2 3 4 5 6do echo $idone 看文件 #!/bin/bashdir=$(ls /etc) for i in $dirdo echo $id ...

  3. Hadoop学习3--安装ssh服务

    题前语:为什么要安装这个东西呢? 是因为我们要在多台机器之间通信,这个服务就相当于支持这种通信的一个桥梁,打个比喻,相当于windows里,通过远程桌面连接到其他机器. 所以,安装这个服务,的目的是: ...

  4. Akka(二) - Future

    1. future的所有方法都是非阻塞立即返回的 (1)future都要有TimeOut和ExecutionContextExecutor这2个隐士参数 (2)打印future object Hell ...

  5. FB Flash Builder 安装错误 ERROR: DW050: - Microsoft Visual C++ 2010 Redistributable Package (x86): Install failed

    这个问题很可能是你的 Microsoft Visual C++ 2010 Redistributable Package (x86) 太新的缘故,所以无法安装成功,导致最终的失败. 在控制面板-程序和 ...

  6. [物理学与PDEs]书中的错误指出

    记号意义: P--Page, 第几页; L--Line, 顺数第几行; LL--Last Line, 倒数第几行. P 64 L 1 ``15)'' should be ``14)''. P 70 L ...

  7. javascript中标签与break和continue的配合使用

    var num = 0; outermost: for (var i=0; i<10; i++) { for (var j=0; j<10; j++) { if (j==5 || i==5 ...

  8. AD按键-矩阵按键:

    原理:利用数组分压+AD采集: 优点:一个IO口可以做成多个按键,节省IO口(矩阵键盘在>4时优点才能体现出来):可备用作为AD基准输入. 缺点:不能做成组合按键(或者电阻要精确选择):且离IO ...

  9. JAVA CAS原理深度分析

    参考文档: http://www.blogjava.net/xylz/archive/2010/07/04/325206.html http://blog.hesey.net/2011/09/reso ...

  10. springmvc 对REST风格的支持

    1.PathVariable注解 用于映射url的占位符到目标方法的参数中 例子: @RequestMapping("/testPathVariable/{id}") public ...