0

Hi.

I need to capture and store the time in database whenever there is application or approval is submitted. (in 24 hours time format)

I've tried time() to capture time and strftime("%H:%M", $timenow) to retrieve and dispaly the time.

However, the hour for the time is incorrect.

Some questions I would like to ask:

i. By using time(), where is the time retrieved from? Is it from our computer time or somewhere else?

ii. The error is hour shows a constant difference of 8 hour with the actual time (I've tried several time values by changing the time from my computer and observe the output from system). Is this because of timezone?

iii. And most of all, is there anyway to help me solve this problem?

Thanks in advance.

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by lcyew
0

the time is from php-server side.

because of timezone.

you can use this function before time();

date_default_timezone_set

(PHP 5 >= 5.1.0)

date_default_timezone_set — Sets the default timezone used by all date/time functions in a script

bool date_default_timezone_set ( string $timezone_identifier )

<?php
date_default_timezone_set('America/Los_Angeles');

$script_tz = date_default_timezone_get();

if (strcmp($script_tz, ini_get('date.timezone'))){
    echo 'Script timezone differs from ini-set timezone.';
} else {
    echo 'Script timezone and ini-set timezone match.';
}
?>
0

Thank you very much dream love. I 've solved my problem.

Code modified from what dream love told:

date_default_timezone_set('Asia/Kuala_Lumpur');

$script_tz = date_default_timezone_get();
$timenow = time();
echo strftime("%H:%M", time());
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.