在eclipse的 Preference -> Java -> Code Style -> Code Templates 的javadoc中,我们往往会自定义自己的javadoc的模板。如下:
/** * ClassName: ${type_name} <br/> * @author ${user} * @version 1.0 * Create Time: ${date} ${time} <br/> * Description: ${todo} 类的实现描述 */
这个时候会出现一点小问题,那就是变量 ${date} 会生成“2016年1月1日”这样的中文格式,而变量 ${time} 则会生成"上午9:00"这样的格式。
由于我是个强迫症患者,而且习惯于自己定义的日期时间格式,上面的带有中文格式的日期显然不是我想要的。那怎么办啊?
改为如下:
/** * ClassName: ${type_name} <br/> * @author ${user} * @version 1.0 * Create Time: ${d:date('yyyy/MM/dd HH:mm:ss')}<br/> * Description: ${todo} 类的实现描述 */
注意上面的日期格式化的方法: ${d:date('yyyy/MM/dd HH:mm:ss')}
【格外注意】这种日期变量进行格式化的方法只支持eclipse 4.x以上版本,原因:eclipse 4.x之前的版本没有这个功能,不支持日期的字符串格式化。
参考资料地址:
https://stackoverflow.com/questions/1131712/how-to-set-the-eclipse-date-variable-format
https://stackoverflow.com/questions/32119571/templates-in-eclipse