how to get correct current time with php?

1

I am reading the current time with

date("H:i:s");

and it goes ahead one hour, I searched and I put the html

date_default_timezone_set('America/Caracas');

but when you apply that, it goes back half an hour to the actual current time, how can I fix it?

    
asked by Gerardo Simancas Matos 24.03.2018 в 18:58
source

2 answers

2

I give you two examples one for my pa + is and one for yours and see how it is used

With the following you avoid complex configurations that may be unnecessary

Make sure that the order of declaration of sentences follows the examples I show you

<?php

date_default_timezone_set('America/Mexico_City');
echo date("H:i:s");

Now for yours in Venezuela and both works perfect

<?php
date_default_timezone_set('America/Caracas');
echo date("H:i:s");

With the default_timezone_set () function you only need to pass the place as a text string and this will work

    
answered by 24.03.2018 в 19:24
1

You can try modifying the lines in your php.ini and restart your apache so that it takes the new values.

    [Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/Caracas
    
answered by 24.03.2018 в 19:17