一个时区到另一个时区的转换 [英] One time zone to another time zone conversion

查看:66
本文介绍了一个时区到另一个时区的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用

例如我想转换

使用 标签将 CTS 转换为 GMT+05:30(或 IST)

CTS to GMT+05:30(or IST) using <s:date> tag

在我的数据库中,我添加了相对于 GMT 的日期和用户时区值.我的数据库服务器显示时区 CTS(我无法更改它).在这里,我想将日期从 CTS 时区转换为用户时区,即 GMT+05:30(或 IST)或存储在数据库中的用户时区

In my database I have added date and user time zone value with respect to GMT. my data base server is showing time zone CTS(I am unalbe to chage it). Here I would like to convert date from CTS time zone to user time zone that is GMT+05:30(or IST) or users time zone stored in database

推荐答案

对于印度标准时间,方法如下:

For Indian Standard Time, this is the way:

<s:date name = "yourDate" 
      format = "dd/MM/yyyy HH:mm:ss a" 
    timezone = "GMT+05:30" />

在对此相关问题的评论中,您可以阅读处理此问题时可能遇到的常见错误.

In the comments to this related question, you can read about common mistakes you might encounter when dealing with this.

日期没有时区.日期只是自特定时间点(EPOCH:01-01-1970,00:00:00 UTC)以来的毫秒数.

A Date has no TimeZone. A date is just a number of milliseconds since a specific point in time (EPOCH: 01-01-1970, 00:00:00 UTC).

当您将日期保存到数据库中时,您只是保存了那个长整数.如果您的数据库具有特定的时区,则意味着当您对其运行查询时,它将使用该时区格式化用于人类表示的日期.在您的数据库、您的 AS、您的框架中也有 TimeZone 设置.但是在整个链中,Date 始终保持相同的 Date 对象,只是表示方式不同.

When you save a Date into a database, you are just saving that Long number. If your database has a specific TimeZone, it means that when you will run a query on it, it will format the Dates for human representation with that TimeZone. There are TimeZone settings in your DB, in your AS, in your framework too. But through the whole chain, the Date remains always the same Date object, just represented differently.

许多数据库允许您保存时区信息和日期.但既然你说:

Many databases allows you to save the TimeZone informations along with the date. But since you said:

在我的数据库中,我添加了相对于 GMT 的日期和用户时区值.

那你完全可以忽略

我的数据库服务器显示时区 CTS

my data base server is showing time zone CTS

只需获取该日期,并使用提供的代码将其格式化为所需的时区.

Just take that Date, and format it with your desired TimeZone, with the code provided.

如果这只是让您感到困惑(采用 GMT 日期,在您的数据库可视化工具中显示为 CTS,并在浏览器中显示为 IST),则使用三个不同的时区在操作中将该日期记录打印三次,以便整个链之间的匹配,这将帮助您调试应用转换的位置和方式.

If this is just confusing you (taking GMT dates, shown as CTS in your DB visualizer, and shown as IST in the browser), then log-print that Date three times in the Action using the three different TimeZones, to have a match between the whole chain, that will help you debugging where the conversions are applied and how.

这篇关于一个时区到另一个时区的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆