PHP code example of raphaelb / timezones

1. Go to this page and download the library: Download raphaelb/timezones library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

raphaelb / timezones example snippets


Raphaelb\Timezones\TimezonesServiceProvider::class,
'Timezones'  => Raphaelb\Timezones\Facades\Timezones::class

use Raphaelb\Timezones\Facades\Timezones;

class User {

    // Accessors in model class.
    
    /**
     * Get created_at attr.
     * @param $date
     * @return string
     */
    public function getCreatedAtAttribute($date)
    {
        return app('timezones')
            ->toTimezone($date, 'gmt')
            ->format('d-m-Y H:i:s');
    }

    /**
     * Get updated_at attr.
     * 
     * @param $date
     * @return string
     */
    public function getUpdatedAtAttribute($date)
    {
        return app('timezones')
                ->toTimezone($date, 'gmt')
                ->format('d-m-Y H:i:s');
    }
    
    /**
     * Or inject a format when you know the given one. 
     * Otherwise Carbon will fail. 
     */
    public function time()
    {
        // Constructor accepts a different format for your needs.
        $time = new Timezones('m-d-Y H:i:s');
        return $time->toTimezone('09-03-2016 16:00:00', 'EST');
    }
        
}