通过Carbon获得来自其他时区的UTC [英] Get UTC from another timezone with Carbon
本文介绍了通过Carbon获得来自其他时区的UTC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果使用其他时区,如何使用 Carbon 获取UTC日期?
How do I get the UTC date with Carbon if I use another timezone?
$timestamp = '2014-02-06 16:34:00';
Carbon::createFromFormat('Y-m-d H:i:s', $timestamp)->timezone('Europe/Stockholm');
我使用Europe/Stockholm
时区创建.如何从中获取UTC日期(2014-02-06 15:34)?
I create with a Europe/Stockholm
timezone. How do I get the UTC date from that (2014-02-06 15:34)?
推荐答案
您可以通过以下方式更改时区:
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');
这篇关于通过Carbon获得来自其他时区的UTC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文