CodeIgniter date - wrong time

2019-09-08 14:49发布

I'm using:

date("d-m-Y h:i:s")

in my controller, but the time is later than actual time. For example, now in my country it's 01:02, date return 20-06-2015 01:06:38.

How to fix it?

4条回答
我欲成王,谁敢阻挡
2楼-- · 2019-09-08 15:24

1st Step : Go to config/config.php and write

//specify your region 
date_default_timezone_set('Europe/Warsaw');

2nd step: now you can use your time

date("d-m-Y h:i:s") //for 21/12/2010 20:12:00
date("h:i:s") //for 12:12:11 time only 
查看更多
Rolldiameter
3楼-- · 2019-09-08 15:38

Your time zones are probably off, this will help you.

http://php.net/manual/en/function.date-default-timezone-set.php

查看更多
走好不送
4楼-- · 2019-09-08 15:42

Place timezone on the top of the config.php file above base_url

date_default_timezone_set('Europe/Warsaw');

Then refresh server

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

date_default_timezone_set('Europe/Warsaw');

/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
|   http://example.com/
|
| If this is not set then CodeIgniter will try guess the protocol, domain
| and path to your installation. However, you should always configure this
| explicitly and never rely on auto-guessing, especially in production
| environments.
|
*/
$config['base_url'] = 'http://localhost/project/';
查看更多
Lonely孤独者°
5楼-- · 2019-09-08 15:47

If you can change the hooks settings in your config file from TRUE to FALSE that should help with your issue.

Except if you have a very important need for the hooks to be enabled you should be very fine this way.

$config['enable_hooks'] = TRUE;

change to:

$config['enable_hooks'] = FALSE;

I hope this helps you.

查看更多
登录 后发表回答