使用频率 | 中低 |
复杂程度 | 中 |
所属模块 | Date |
成员类型 | 原型扩展 |
format方法用于对日期或者时间按照指定格式进行格式化.
y : 年份
M : 月份
d : 日期
h : 小时
m: 分钟
s : 秒
q: 季节
S: 毫秒
String format(String pattern);
类型 | 描述 |
String | 预格式化的字符串 |
new Date().format("yyyy-M-d h:m:s");
new Date().format("yyyy-MM-d h:m:s");
new Date().format("yy-MM-d h:m:s");
new Date().format("MM/d/yy h:m:s");
"2015-8-11 17:41:42"
"2015-08-11 17:42:10"
"15-08-11 17:42:32"
"08/11/15 17:43:6"