Latest web development tutorials

<fmt:timeZone> 標籤

JSP 標準標籤庫 JSP標準標籤庫

<fmt:timeZone>標籤用來指​​定時區,供其它標籤使用。



語法格式

<fmt:setLocale value="<string>" variant="<string>" scope="<string>"/>

屬性

<fmt:timeZone>標籤有如下屬性:

屬性 描述 是否必要 默認值
value 時區


實例演示

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ 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 标签</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>

運行結果如下:

fmt-timezone


JSP 標準標籤庫 JSP標準標籤庫