| 
 时间格式化   1.  Java 类中: SimpleDateFormat类: SimpleDateFormat允许进行格式化(日期 -> 文本)、解析(文本 -> 日期)和规范化,使得可以选择任何用户定义的日期-时间格式的模式 
SimpleDateFormat函数语法: 
 
                     字母  日期或时间元素  表示  示例  G  Era 标志符  Text  AD   
y  年  Year 1996; 96   
M  年中的月份  Month July; Jul; 07   
w  年中的周数  Number 27   
W  月份中的周数  Number 2   
D  年中的天数  Number 189   
d  月份中的天数  Number 10   
F  月份中的星期  Number 2   
E  星期中的天数  Text Tuesday; Tue   
a  Am/pm 标记  Text PM   
H  一天中的小时数(0-23)  Number  0   
k  一天中的小时数(1-24)  Number  24   
K  am/pm 中的小时数(0-11)  Number  0   
h  am/pm 中的小时数(1-12)  Number  12   
m  小时中的分钟数  Number 30   
s  分钟中的秒数  Number 55   
S  毫秒数  Number 978   
z  时区  General time zone  Pacific Standard Time; PST; GMT-08:00   
Z  时区  RFC 822 time zone  -0800 
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss"); DateFormat df =new SimpleDateFormat("yyyy/MM/DD"); 
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); SimpleDateFormatformatter = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormatformatter = new SimpleDateFormat("yyyyMMdd HHmmss"); 注:一定要注意两者区别:yyyy-MM-dd HH:mm:ss ; yyyy-MM-dd hh:mm:ss 
 
     2.  Jsp页面中: a)        方法一:(使用 Struts2中的<s:date />标签) <s:date name="datetime" format="yyyy年mm月dd日"/> 其中,datetime为Action中的private datetime 变量,只要Action中有此变量,即可使用。 b)     方法二:(使用JDK) <%SimpleDateFormat s = newSimpleDateFormat("yyyyMMddHHmmss"); Date date = new Date();%> <%=s.format(date)%>     3.根据以上时间的应用,下面介绍JEECG里面使用的日期格式化 例:<t:dgColtitle="时间名称 " field="显示内容 " formatter="yyyy/MM/dd"></t:dgCol>     这里主要是formatter进行格式化方法: 
formatter="yyyy/MM/dd" 
formatter="yyyy-MM-dd" 
formatter="yyyy-MM-dd hh:mm:ss " 
 
  
   
     
           
 
    
 |