Carbon::now() with time-offset result in different behaviors

浪尽此生 提交于 2019-12-11 01:38:01

问题


I'am using Carbon for manipulating dates in a laravel project.

Carbon::now('+5:30');

Above code is working fine in local environment but not in development environment.

This is what i get on dd(Carbon::now('+5:30'));

1 - IN LOCAL ENVIRONMENT php version - 5.6.3

2 - IN DEVELOPMENT ENVIRONMENT php version - 5.5.9-1ubuntu4.14

But both environment behaves same if i use timezone name instead of time-offset like,

 Carbon::now('Asia/Tokyo');

Is this something about the php-version or something else?


回答1:


I have an answer for you after searching for related issues.

It seems that PHP version 5.5.9 had a bug:

https://stackoverflow.com/a/14069062/5912664

So you can't use that method with Carbon, but the following should work:

Carbon::now()->addHours(5)->addMinutes(30);

You can place your servers timezone in there for added accuracy:

Carbon::now(date_default_timezone_get())->addHours(5)->addMinutes(30);



回答2:


you can change in

'timezone' => 'UTC'

This time zone must match to your country zone.So replace this UTC with your current zone.



来源:https://stackoverflow.com/questions/36447379/carbonnow-with-time-offset-result-in-different-behaviors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!