Jump to content
php.lv forumi

Recommended Posts

Posted (edited)

Kur ir kļūda?

 

function combine_date_time($date, $time)
{
$t = explode(".",$time);
$d = explode(".",$date);
// echo $t[0].' '; echo $t[1].' '; echo $d[0].' '; echo $d[1].' '; echo $d[2].' ';
return mktime($hour=$t[0], $minute=$t[1], $second=0, $month=$d[1], $day=$d[0], $year=$d[2]);
}

 

$t = '10.50';
$d = '21.10.2009';  
echo combine_date_time($d, $t);

 

Rezultāts ir 1256111400, bet it kā jābūt 1256122200 (vismaz tā šeit rāda - http://www.onlineconversion.com/unix_time.htm)

 

+ cik saprotu, tad te funkcijā vēl trūkst apstrāde, kas noņem priekšējās nulles (piemēram, laikam 01 jāpāraisa par 1 utt).

Edited by renathy
Posted

strftime() zin tādā veidā, ka der tikai timestamp formāts.

The optional timestamp parameter is an integer Unix timestamp that defaults to the current local time if a timestamp is not given. In other words, it defaults to the value of time().
Posted (edited)

Aleksejs: Es biju domājusi strtotime().

 

Marcis: tavs ietektais strtotime variants man nestrādā.

 

ja

date = 15.11.2009

time = 21.45

 

tad strtotime rezultāts ir 1258339500

bet jābūt 1268343900

Edited by renathy
Posted

Ui, nu labi. Nav jābūt tā kā es uzrakstīju.

Bet nav jābūt arī tā kā tā funkcija dod - 1258339500.

 

echo date("d.m.Y H.i",1258339500);

16.11.2009 04.45

 

nevis 15.11.2009 21.45

Posted

The function expects to be given a string containing a US English date format.

un

This function will use the TZ environment variable (if available) to calculate the timestamp. Since PHP 5.1.0 there are easier ways to define the timezone that is used across all date/time functions. That process is explained in the date_default_timezone_get() function page.

 

Es parasti ar explode() sadalu padoto teksta virkni trijās daļās un tad tās iebaroju mktime() funkcijai kā attiecīgos parametrus.

Posted

Viss kā parasti ir pareizi...

echo strtotime('16.11.2009 04.45'); // 1258339500
echo strtotime('15.11.2009 21.45'); // 1258314300
echo date("d.m.Y H.i",1258339500); // 16.11.2009 04.45

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...