码迷,mamicode.com
首页 > 编程语言 > 详细

【笔记——JAVA】关于java的时间格式化

时间:2014-09-05 11:19:41      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:style   color   os   java   for   sp   c   时间   new   

以前老是忘记,现在做个笔记

Date time = new Date();
Formatter formatter = new Formatter();

//这里就是格式化,每一个格式化参数,就得加一个格式化对象(可以是同一个格式化对象)
formatter.format("%tF %tT", time,time);
String ti = formatter.toString();

//记得关闭
formatter.close();
System.out.println(ti);

 

格式化表 格式:%[格式参数] 比如 %F 把时间格式化为 年-月-日的形式

a  星期简称

A  星期全称

b  月份简称

B  月份全称

c  天-月-日-时-分-秒-时区-年

F  年-月-日

r  H:M:S(AM)

R  H:M:S

其余自行查水表

 

【笔记——JAVA】关于java的时间格式化

标签:style   color   os   java   for   sp   c   时间   new   

原文地址:http://www.cnblogs.com/kirno/p/3957623.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!