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

2019-07-09 23:11发布

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

enter image description here

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

enter image description here

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?

2条回答
狗以群分
2楼-- · 2019-07-09 23:49

you can change in

'timezone' => 'UTC'

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

查看更多
闹够了就滚
3楼-- · 2019-07-09 23:52

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);
查看更多
登录 后发表回答