JSTL <fmt:setTimeZone> 标签用于设定默认时区。
JSP <fmt:setTimeZone> 标签的语法如下:
- <fmt:setTimeZone value="timeValue" [scope="page|request|session|application"] var="varname" />
其中:
<fmt:setTimeZone> 标签的简单实例如下。
- <%@ 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"%>
- <!DOCTYPE html>
- <html>
- <head>
- <title>城东书院(www.cdsy.xyz)</title>
- </head>
- <body>
- <c:set var="str" value="<%=new java.util.Date()%>" />
- <fmt:setTimeZone value="GMT+8" />
- <fmt:formatDate value="${str}" type="both" dateStyle="full"
- timeStyle="full" var="dateref" />
- <h3>北京时间:${dateref}</h3>
- </body>
- </html>
页面输出内容如下: