我正在写一个基于web的前端到一个数据库(PHP/Postgresql),其中我需要存储各种日期/时间。时间意味着总是以本地时间在客户端输入,并以本地时间显示。出于存储目的,我将所有日期/时间存储为整数(UNIX时间戳),并将其规范化为UTC。一个特定的字段有一个限制,即填写的时间戳不允许在将来出现,所以我尝试使用数据库约束...
CONSTRAINT not_future
CHECK (timestamp-300 <= date_part('epoch', now() at time zone 'UTC'))
在浏览器和服务器之间时间稍微不同步
我完全搞不懂PHP UTC/本地时间转换。有些函数隐式地转换时间,有些则不。啊!
比方说,我有以下PHP代码:
$timestamp = strtotime("2016-05-13 09:26:30"); //From MySQL date format
//$timestamp returned is 1463153190
如果我 1463153190到UTC时间,它就变成了05/13/2016 @ 3:26pm (UTC)。为什么?
如何获得一个函数来将时间从字符串转换为时间戳一对一,而没有任何时区恶作剧?
我在php-手册"date“上找到了这个函数。
<?php
// Converts a unix timestamp to iCal format (UTC) - if no timezone is
// specified then it presumes the uStamp is already in UTC format.
// tzone must be in decimal such as 1hr 45mins would be 1.75, behind
// times should be represented as negative decimals 1
我有一个移动应用程序和rest服务。移动应用程序将生成并向web服务提供UTC日期、时间和时区。我需要使用php将这两个值存储到mysql中。
我正在从一个远程源获取日期时间,所以我不能使用mysql的UTC_TIMESTAMP()来生成‘当前’utc时间。
我有一个包含2列的表: created (DATETIME)和timezone (VARCHAR)
在PHP中,我将收集以下内容:
$created = "2010-09-30 12:31:10"; //Actual UTC time
$timezone = "America/Los_Angeles"
IN
我有一个数据集,如下所示:
datetime count
18:28:20.602 UTC DEC 08 2016 1
20:42:32.017 UTC DEC 08 2016 5
15:33:40.691 UTC DEC 08 2016 1
17:11:54.008 UTC DEC 08 2016 3
20:28:57.861 UTC DEC 08 2016 0
.
我有一个JSON响应,它返回created字段的UNIX时间戳值:
"created_utc": 1395800038.0
---
// The type I use to marshal the response JSON.
// I can't use string because Golang complains the JSON is a float.
type Submission struct {
CreatedUtc float32 `json:"created_utc"`
}
我想将它转换为一