PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 26, 2022

[FIXED] Carbon auto increments time by 11 minutes on parse

 January 26, 2022     laravel, laravel-5, php-carbon, timezone, timezone-offset     No comments   

Issue

I am using Carbon with Laraveal, my local timezone is in IST. I am passing the below ISO string from the UI.

2019-11-22T03:00:00.000Z

When parsed on the server with the below syntax:

\Carbon\Carbon::parse($value)->timezone($this->user->timezone)->format('Y-m-d H:m:s');

The output I am getting is :

2019-11-22 03:11:00

Don't know why I am getting the additional 11 minutes in the time. UI and Server both runs in my local machine. Don't know what's causing the 11 minutes addition.


Solution

->format('Y-m-d H:m:s');

should be

->format('Y-m-d H:i:s');

Notice the m for months and i for minutes.

See PHP docs for formats



Answered By - KFoobar
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing