renathy Posted March 31, 2009 Report Posted March 31, 2009 (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 March 31, 2009 by renathy Quote
marcis Posted March 31, 2009 Report Posted March 31, 2009 function combine_date_time($date,$time){ return strtotime($date.' '.$time); } $t = '10:50'; $d = '21.10.2009'; echo combine_date_time($d, $t); Quote
renathy Posted March 31, 2009 Author Report Posted March 31, 2009 bet kā strtime zina kādā formātā ir tas date un time, jo man date ir, piemēram, 01.10.2008? Quote
marcis Posted April 1, 2009 Report Posted April 1, 2009 Godīgi? Nav ne jausmas kā viņš to zin, galvenais, ka strādā (: Quote
renathy Posted April 1, 2009 Author Report Posted April 1, 2009 :) Ok Bet kā dabūt atpakaļ - no tā timestampa dabūt atpakaļ $date un $time? Quote
renathy Posted April 1, 2009 Author Report Posted April 1, 2009 Bubu: varbūt tu zini kā strtime zina kādā formātā ir tie datumi un laiki (mans posts divus atpakaļ)? Quote
Aleksejs Posted April 1, 2009 Report Posted April 1, 2009 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(). Quote
renathy Posted April 2, 2009 Author Report Posted April 2, 2009 Par strftime ir skaidrs, bet kā zina strtime? Quote
Aleksejs Posted April 2, 2009 Report Posted April 2, 2009 man saka, ka nav tādas funkcijas: strtime() Quote
renathy Posted April 2, 2009 Author Report Posted April 2, 2009 (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 April 2, 2009 by renathy Quote
marcis Posted April 2, 2009 Report Posted April 2, 2009 Labi, ka jābūt tā kā tu saki? echo date("d.m.Y H.i",1268343900); // Output: 11.03.2010 23.45 Quote
renathy Posted April 2, 2009 Author Report Posted April 2, 2009 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 Quote
Aleksejs Posted April 2, 2009 Report Posted April 2, 2009 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. Quote
marcis Posted April 2, 2009 Report Posted April 2, 2009 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.