Carbon::now() is not using UTC

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Understanding Timezones and Carbon::now() in Your Laravel Applications Time is one of the most fundamental aspects of software applications. It plays an essential role in scheduling, coordinating tasks, and ensuring data consistency across different parts of a system. In Laravel, you can manipulate time using the Carbon library for various purposes. However, as we shall see, you might face issues when handling timezones. Let's first understand how Carbon::now() works in general. When Carbon::now() is called, it returns a new instance of Carbon object representing the current date and time of your computer. By default, this instance does not consider the offset between local time and UTC (Coordinated Universal Time). If you wish to work with UTC time consistently across all your Laravel applications regardless of the user's location, you need to set up your application configuration accordingly. Here is a comprehensive example code for handling timezone in your Laravel project: 1. Setting Up Your Laravel Project for a Specific Time Zone: In your `config/app.php` file, add or update the following line: ```PHP 'timezone' => 'UTC', // Or any specific time zone you desire ``` 2. Using Carbon::now() to Obtain UTC Time in Your Code: In your controller or model code, as shown below: ```PHP $log->dateRequest = Carbon::now(); ``` 3. Displaying the Time Based on Local Time Zone in User-Facing Pages: If you want to display local time for users on your website, you can convert the UTC time to their local time in your view code using the following method: ```PHP $localTime = Carbon::now()->setTimezone('Asia/Manila'); // Or any other specific time zone echo $localTime->format('H:i'); // Displays the current local time as "21:00" (9:00pm) in Asia/Manila time zone. ``` 4. Managing User Time Zone Preferences for Customized Experiences: If you want to store and respect the user's time zone preference, you can use session or cookie data stored in your application. For instance, in your controller, you might have: ```PHP $userTimeZone = Session::get('timezone', 'UTC') // Default UTC if not set by the user $localTime = Carbon::now()->setTimezone($userTimeZone); echo $localTime->format('H:i'); // Displays the current local time as per the user's preference. ``` Always remember that working with time and date in your Laravel applications involves complexities related to timezones, DST (Daylight Saving Time), and UTC offsets. To ensure a seamless experience for you and your users, take the necessary steps to handle these aspects properly. For more information on working with Carbon in Laravel, refer to the official documentation: https://laravelcompany.com/blog/datetime-and-timezones-in-your-laravel-applications In summary, using Carbon::now() does not automatically return UTC time by default. To achieve this behavior, properly configure your application settings and handle time zone conversions in your code accordingly. This ensures accurate handling of date and time across the board in your Laravel applications.