问题标签 [timestamp-with-timezone]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
38247 浏览

postgresql - 如何使用准备好的语句在 postgresql 中插入带时区的时间戳?

我正在尝试使用准备好的语句将包含日期、时间和时区的字符串插入到带有我的数据库的时区字段的时间戳中。

问题是 Timestamp.valueof 函数没有考虑字符串包含的时区,因此会导致错误。接受的格式是 yyyy-[m]m-[d]d hh:mm:ss[.f...] ,其中没有提及时区。

那是导致错误的确切代码:

pst.setTimestamp(2,Timestamp.valueOf("2012-08-24 14:00:00 +02:00"))

有什么办法可以克服吗??提前致谢!

0 投票
2 回答
8757 浏览

postgresql - 如何在准备好的语句中传递带有''(时间戳)的字符串?

我正在尝试执行以下查询

我想将时间戳作为变量传递。

我的时间戳列是带有时区的时间戳类型。

你知道如何做到这一点吗?

当我这样做时......(Java,Postgresql)

我在“$1”处或附近收到语法错误

无论如何我可以克服这个错误吗?先感谢您!!

更新:我尝试通过以下方式使用 setTimestamp ......

我想数据库中的正确值应该是(关于我的本地时区是 EET (+02))

2012-01-05 11:00:00 +02

但是使用 pgadmin 我检查了值,我得到了

2012-01-05 14:00:00 +02

有什么建议么?

0 投票
1 回答
2642 浏览

python - 将特定时区中的日期时间对象转换为该时区中的纪元秒

例如:

>>> print dt
2012-12-04 19:00:00-05:00

如您所见,我有这个 datetime 对象如何在 GMT -5 中将此 datetime 对象转换为纪元秒。

我该怎么做呢?

0 投票
1 回答
241 浏览

python - 带有时区字段/模板的日期时间输出奇怪的行为

时区设置settings.py:

记录在数据库表中(postgresql 9.1,带时区的时间戳:

2012-12-19 15:30:51.164368+04

Django 日期过滤器:

在所有这些操作之后,模板中的日期时间文件输出为:

19.12.2012 11:30:51

为什么会发生这种情况?为什么 django 不使用 TZ 信息?

0 投票
2 回答
22078 浏览

sql - 更改表中数据的日期和时间戳格式

我们有一个巨大的 Oracle 数据库,其中包含具有日期和时间戳的数据。现在我们正在使用mm-dd-yyyy format for date and EST Time zone for time stamp.

现在我们需要更改date format as yyyy-mm-dd and time stamps should be GMT timezone. 我们需要将表中已经存在的数据以及新插入的数据更改为这种新格式。

关于如何实现这一目标的任何帮助?

0 投票
1 回答
263 浏览

sql - Unexpected results from SQL query with BETWEEN timestamps

I have created a little test app to track down a problem I experienced with Postgres on Heroku: http://snippi.com/s/xd511rf

As you can see in line 49, I want to retrieve all entries created today. This would be the first two items of my test data with the Ruby Gem DataMapper.

When I run this app on my notebook (Ubuntu 12.10, HP, Ruby 1.9.3) everything I get this result, which is right:

In my debug console this SQL query is logged:

But after pushing the app to Heroku a very strange error occurrs. When I run it now (http://afternoon-everglades-4239.herokuapp.com/) this is the response:

Why is it empty?

The data is definitely in the database which is proved by this Dataclip from Heroku: https://dataclips.heroku.com/hygziosyxwperyctwfbhjzgbzhbj

Also when I run the SQL command manually via ´heroku pg:psql´ it actually works with this output:

The logs do not contain any errors or further information. I have used a Remote Heroku PostgreSQL Database in both cases (Production and Local).

So why does this not work?

0 投票
1 回答
131 浏览

php - 使用 unix 时间戳和时区

时区和时间戳让我感到困惑,所以我希望有人能回答我的问题:)

假设我有一个 Python 脚本,它解析 RSS 提要,使用以下代码将日期值转换为时间戳并将其存储在数据库中:

现在,当我从 PHP 中的数据库检索该记录并运行以下代码时,PHP 是否假定时间戳为 UTC-0 并自动将时区偏移到东部时间?

我发现我的日期有奇怪的问题,所以我想知道是否有人可以帮助我就如何正确转换和存储 rss 提要时间戳提供建议。我可以在某处跨越这行代码,所以我应该把它放在我的脚本顶部吗?

0 投票
2 回答
1338 浏览

sql - 如何从时间戳中提取一致的年份

我正在尝试使用 Postgres 函数extract()timestamptz列中获取年份,但得到了意想不到的结果。我预计它将使用 UTC,但似乎使用系统的本地时区(在我的情况下为 EST)。无论时间戳或系统的时区是什么,如何获得extract返回 UTC 的函数?

示例 1:

示例 2:

0 投票
1 回答
3224 浏览

javascript - 谷歌地图时区获取当地时间

我正在尝试使用谷歌时区 API。我提供经度和纬度,API 给我时区。

如何使用以下值(dstOffset 和 rawOffset)获取本地时间?

这是Json

我已经尝试过这个 javascript 函数,但我没有得到正确的时间。

谢谢你的帮助 !

0 投票
3 回答
4704 浏览

php - PHP 日志文件时区

我正在玩 FengOffice 项目,我是 PHP 的初学者。我想将日志从 GMT 更改为香港时间。但即使我设置

或者

PHP 日志仍然显示 GMT 时间,应用程序日志也是如此。

我还尝试在代码中更改时区:

但没有任何效果。任何人都可以帮忙吗?非常感谢。