Custom Date tag
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的更多相关文章
- Tag file
JSP 2.0 引入 Tag file ,tag file 以 tag 或 tagx 为后缀,它们可以包含其他资源文件:一个被其他文件包含的 tag file 应该以 tagf 为后缀. 如同JSP页 ...
- HTML Custom Elements (v1)
HTML Custom Elements (v1) https://developers.google.com/web/fundamentals/web-components/customelemen ...
- snakeyaml - Documentation.wiki
SnakeYAML Documentation This documentation is very brief and incomplete. Feel free to fix or improve ...
- Mybatis Generator生成数据库自带的中文注释
1.相关jar包 <!-- mybatis生成 jar包 --> <dependency> <groupId>org.mybatis.generator</g ...
- 关于 mybatis-generator自定义注释生成 使用DefaultCommentGenerator重写来完成
项目里新建表时model,mapper以及mapper.xml基本都是用Mybatis Generator(以下简称为MBG)自动生成的,但是MBG自动生成的model的注释实在有点非人类,至少中国人 ...
- Mybatis Generator的model生成中文注释,支持oracle和mysql(通过实现CommentGenerator接口的方法来实现)
自己手动实现的前提,对maven项目有基本的了解,在本地成功搭建了maven环境,可以参考我之前的文章:maven环境搭建 项目里新建表时model,mapper以及mapper.xml基本都是用My ...
- vue源码逐行注释分析+40多m的vue源码程序流程图思维导图 (diff部分待后续更新)
vue源码业余时间差不多看了一年,以前在网上找帖子,发现很多帖子很零散,都是一部分一部分说,断章的很多,所以自己下定决定一行行看,经过自己坚持与努力,现在基本看完了,差ddf那部分,因为考虑到自己要换 ...
- mybatis根据数据库表结构自动生成实体类,dao,mapper
首先, pom需要引入 <!-- mysql --> <dependency> <groupId>mysql</groupId> <artifac ...
- 腾讯发布新版前端组件框架 Omi,全面拥抱 Web Components
Omi - 合一 下一代 Web 框架,去万物糟粕,合精华为一 → https://github.com/Tencent/omi 特性 4KB 的代码尺寸,比小更小 顺势而为,顺从浏览器的发展和 AP ...
随机推荐
- <limits.h>和<float.h>
头文件<limits.h>中定义了用于表示整类型大小的常量.以下所列的值是可接受的最小值,实际系统中可能有更大的值. CHAR_BIT char类型的位数 CHAR_MAX UCHAR_M ...
- 如何生成RestFul Api文档
Web API文档工具列表Swagger ——Swagger框架可以通过代码生成漂亮的在线API,甚至可以提供运行示例.支持Scala.Java.Javascript.Ruby.PHP甚至 Actio ...
- Perl参考函数
这是标准的Perl解释器所支持的所有重要函数/功能的列表.在一个函数中找到它的详细信息. abs - 绝对值函数 accept - 接受传入的socket连接 alarm - 调度一个SIGALRM ...
- c++中的peek函数
c++中 cin.peek()函数 其返回值是一个char型的字符,返回值是指针指向的当前字符, 但是只是观测,指针任停留在当前位置,并不后移.如果要访问的字符是文件结束符,则函数值是EOF(-1); ...
- Java 中Timer和TimerTask 定时器和定时任务使用的例子
转自:http://blog.csdn.net/kalision/article/details/7692796 这两个类使用起来非常方便,可以完成我们对定时器的绝大多数需求 Timer类是用来执行任 ...
- 我的Android最佳实践之—— 常用的Intent.Action(转)
1.从google搜索内容 Intent intent = new Intent(); intent.setAction(Intent.ACTION_WEB_SEARCH); intent.putEx ...
- C#程序集编译输出XML文档的作用
下图是ClassLib1类库的项目属性 /// <summary> /// 读取INI文件 /// </summary> /// <param name="Se ...
- @RequesParam注解源码解析
- nginx软负载的搭建
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器,在高连接并发的情况下Nginx 是 Apa ...
- GL_GL系列 - 预算管理分析(案例)
2014-07-09 Created By BaoXinjian