[英]UTC date not changing in IST date format in PHP
As based on REST API page documentation the date is in UTC format as yyyy-MM-dd'T'HH:mm:ss (Eg: 2017-01-02T08:12:53)
When I hit the API, I am getting the date as 1619693307000
. As based on REST API page documentation the date is in UTC format as
yyyy-MM-dd'T'HH:mm:ss (Eg: 2017-01-02T08:12:53)
When I hit the API, I am getting the日期为1619693307000
。 Converted this date using strtotime()
in PHP.使用 PHP 中的
strtotime()
转换此日期。 What is the correct way to convert this date in dmY h:i:s IST
in PHP.在 PHP 中的
dmY h:i:s IST
中转换此日期的正确方法是什么。
I used this code to do the same.我用这段代码来做同样的事情。
<?php echo date("Y-m-d h:i:s", '1619693307000') ?> //OUTPUT: 53296-01-14 01:00:00
The above output is absolutely wrong.上面的output是绝对错误的。 Confusion is to correctly convert UTC to IST zone and what should i do to see the correct output as the date in PHP.
困惑是将UTC正确转换为IST区域,我应该怎么做才能看到正确的output作为PHP中的日期。 I read all threads on this StackOverflow and Google.
我阅读了 StackOverflow 和 Google 上的所有线程。 but all not helpfull.
但都没有帮助。
Please help...请帮忙...
Your timestamp has too many digits, so it's likely in milliseconds.您的时间戳有太多数字,因此可能以毫秒为单位。 This seems to be a common javascript thing.
这似乎是一个常见的 javascript 事情。 So divide by 1000, and I highly recommend using the
DateTime
objects/interfaces rather than the old-style strtotime()
/ date()
/etc functions.所以除以 1000,我强烈建议使用
DateTime
对象/接口而不是旧式strtotime()
/ date()
/etc 函数。
$millis = 1619693307000;
$seconds = $millis / 1000;
$t = new DateTime('', new DateTimezone('Asia/Kolkata'));
$t->setTimestamp($seconds);
var_dump(
$t->format("Y-m-d h:i:s T")
);
Output: Output:
string(23) "2021-04-29 04:18:27 IST"
Also "UTC" is not a format, it's a timezone. “UTC”也不是一种格式,它是一个时区。
2017-01-02T08:12:53
is an ISO8601-format. 2017-01-02T08:12:53
是 ISO8601 格式。 It also has a handy format shortcut:它还有一个方便的格式快捷方式:
var_dump(
$t->format("c")
);
Output: Output:
string(25) "2021-04-29T16:18:27+05:30"
Edit: Different timezone and format:编辑:不同的时区和格式:
$t = new DateTime('', new DateTimezone('UTC'));
$t->setTimestamp($seconds);
var_dump(
$t->format("Y-m-d\Th:i:s")
);
Output: Output:
string(19) "2021-04-29T10:48:27"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.