<fmt:setTimeZone> Etiqueta

JSP 标准标签库Biblioteca de etiquetas estándar de JSP

La etiqueta <fmt:setTimeZone> se utiliza para copiar un objeto de zona horaria a un ámbito especificado.

Formato de sintaxis

<fmt:setTimeZone value="<string>" var="<string>" scope="<string>"/>

Atributos

La etiqueta <fmt:setTimeZone> tiene los siguientes atributos:

Atributo Descripción ¿Es necesario? Valor predeterminado
value Zona horaria Sí Ninguno
var Nombre de la variable para almacenar la nueva zona horaria no Replace default
scope Ámbito de la variable no Page


Demostración de ejemplo

<%@ 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:setTimeZone 标签</title>
</head>
<body>
<c:set var="now" value="<%=new java.util.Date()%>" />
<p>当前时区时间: <fmt:formatDate value="${now}" 
             type="both" timeStyle="long" dateStyle="long" /></p>
<p>修改为 GMT-8 时区:</p>
<fmt:setTimeZone value="GMT-8" />
<p>Date in Changed Zone: <fmt:formatDate value="${now}" 
             type="both" timeStyle="long" dateStyle="long" /></p>
</body>
</html>

El resultado de la ejecución es el siguiente:

当前时区时间: 2016年6月26日 上午11时34分05秒

修改为 GMT-8 时区:

Date in Changed Zone: 2016年6月25日 下午07时34分05秒

JSP 标准标签库Biblioteca de etiquetas estándar de JSP

Otras extensiones