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.

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.';
}
?>

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());

Sorry. Line 4 can be ignored.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.