如何在 JSP 中使用時區?
<fmt:timeZone> 標籤用於指定其主體內的所有標籤將使用的時間區。
屬性
<fmt:timeZone> 標籤具有以下屬性 -
| 屬性 | 描述 | 必需 | 預設 |
|---|---|---|---|
| 值 | 應用於主體的時區 | 是 | 無 |
示例
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/fmt" prefix = "fmt" %>
<html>
<head>
<title>JSTL fmt:timeZone Tag</title>
</head>
<body>
<c:set var = "now" value = "<% = new java.util.Date()%>" />
<table border = "1" width = "100%">
<tr>
<td width = "100%" colspan = "2" bgcolor = "#0000FF">
<p align = "center">
<b>
<font color = "#FFFFFF" size = "4">Formatting:
<fmt:formatDate value = "${now}" type = "both" timeStyle = "long" dateStyle = "long" />
</font>
</b>
</p>
</td>
</tr>
<c:forEach var = "zone" items = "<% = java.util.TimeZone.getAvailableIDs()%>">
<tr>
<td width = "51%">
<c:out value = "${zone}" />
</td>
<td width = "49%">
<fmt:timeZone value = "${zone}">
<fmt:formatDate value = "${now}" timeZone = "${zn}" type = "both" />
</fmt:timeZone>
</td>
</tr>
</c:forEach>
</table>
</body>
</html>上面的程式碼將生成以下結果 -
格式化:2010 年 9 月 23 日 15:09:09 GST | |
| Etc/GMT+12 | 2010 年 9 月 22 日 23:09:09 |
| Etc/GMT+11 | 2010 年 9 月 23 日 00:09:09 |
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP