php 使用 Carbon 从另一个时区获取 UTC
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21607236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:17:04 来源:igfitidea点击:
Get UTC from another timezone with Carbon
提问by Marwelln
How do I get the UTC date with Carbonif I use another timezone?
如果我使用其他时区,如何使用Carbon获取 UTC 日期?
$timestamp = '2014-02-06 16:34:00';
Carbon::createFromFormat('Y-m-d H:i:s', $timestamp)->timezone('Europe/Stockholm');
I create with a Europe/Stockholmtimezone. How do I get the UTC date from that (2014-02-06 15:34)?
我用Europe/Stockholm时区创建。如何从中获取 UTC 日期 (2014-02-06 15:34)?
回答by Marwelln
You can change the timezone with this:
您可以通过以下方式更改时区:
$timestamp = '2014-02-06 16:34:00';
$date = Carbon::createFromFormat('Y-m-d H:i:s', $timestamp, 'Europe/Stockholm');
$date->setTimezone('UTC');

