Jump to content
php.lv forumi

date() problēma


Леший

Recommended Posts

Ir jādabū laiku līdz rītdienai 00:00:00 formātā "H:i:s".

strtotime("tomorrow")-time()

atgriež pareizo sekunžu skaitu, bet

date("H:i:s", strtotime("tomorrow")-time())

piepluso/minuso GMT nobīdi.

Ir idejas, ko ar šo var darīt?

 

EDIT:

Atrisināts (porno, bet strādā):

$tz = date_default_timezone_get();
$time = strtotime("tomorrow")-time();
date_default_timezone_set("GMT");
echo date("H:i:s", $time);
date_default_timezone_set($tz);

Edited by Леший
Link to comment
Share on other sites

strtotime("tomorrow")-time()

Vispār jau šis nav timestamp, bet starpība (sekundes), kas nozīmē, ka vajadzīgās vērtības jāizrēķina matemātiski:

$diff = strtotime("tomorrow")-time();
echo str_pad(floor($diff/3600), 2, '0', STR_PAD_LEFT),':',str_pad(floor(($diff%3600)/60), 2, '0', STR_PAD_LEFT),':',str_pad(floor(($diff%3600)%60), 2, '0', STR_PAD_LEFT);

date() funkcija izvadīs pareizu rezultātu tikai GMT gadījumā, kad laika nobīde stundās ir nulle (šito jau tu pats saprati).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...