【问题标题】:fmt:formatDate and timeZonefmt:formatDate 和 timeZone
【发布时间】:2010-10-25 08:15:02
【问题描述】:

我在 Mysql 数据库中有字段键入 datetime

例如,我使用下一个 Java 代码存储付款日期:

payment.setCreatedOn(new Date(System.currentTimeMillis())); 

在我的视图层中,我使用fmt:formatDate 来格式化日期:

<fmt:formatDate value="${payment.createdOn}" pattern="EEE, dd MMM yyyy HH:mm:ss"/> 

我的服务器在伦敦,我的应用程序的用户在维也纳。时间显示延迟可能是因为不同的时区。我可以在 fmt:formatDate 中使用 timeZone 参数。

timeZone: 时区 表示格式化的时间。

在谷歌搜索后,我认为 Europe/Vienna 的值对 timeZone 参数有效。

有谁知道是否有任何有效时区字符串的列表?

【问题讨论】:

    标签: mysql timezone jstl


    【解决方案1】:

    Sergio - 我敢肯定你早​​就找到了...

    这是homepage for the Olson database 或“zoneinfo”,它是 TZ 信息的权威来源。

    这里有一个nice wiki 用于浏览区域。

    【讨论】:

      【解决方案2】:

      【讨论】:

        【解决方案3】:

        您需要使用国际时间(UTC/Zulu)添加以下调度客户端时间使用,例如“GMT+1”。请参阅此示例。

        将此参数作为参数放入您的服务器以设置UTC时间使用,在这种情况下用于tomcat:

        -Duser.timezone="UTC"

        /* Java */      
        
        @RequestMapping(value = "/web", method = { RequestMethod.POST, RequestMethod.GET })
        public String web(Model model, HttpSession session, Locale locale) {
        
            Date today = new Date();
            model.addAttribute("currentTime", today);
            model.addAttribute("timezone", "GMT+1");
        
            return "web";
        }
        

        要显示日期,请选择您想要的模式(属性)

        /* JSP web */
        
        <fmt:timeZone value="${timezone}">
        <spring:message code="date_format_dateMin" var="pattern"/>
        <fmt:formatDate value="${currentTime}" timeZone="${timezone}" pattern="${pattern}" var="searchFormated" />
        <span class="innerLabel">${searchFormated}</span>   
        </fmt:timeZone>
        
        /* Properties */
        
        date_format_dateMin=yyyy/MM/dd HH:mm
        date_format=yyyy/MM/dd HH:mm:ss    
        date_format2=yyyy/MM/dd
        date_format3_js=yy/mm/dd
        date_format4_time=HH:mm
        date_format4=dd/MM/yyyy HH:mm:ss
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-11-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-01-28
          • 2012-07-28
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多