PHP get daylight saving time - letni cas date(I)
Letní čas tak připočítat hodinu.
Ověření zda je letní čas.
$dst = date("I"); //I (capital i); 0 or 1 if daylight saving time
// example:
$hour = 14;
if(date("I")===1){
$hour = $hour + 1;
}
// OR
$hour = 14 + date("I");
77LW NO topic_id
AD
Další témata ....(Topics)
toString([radix])
/* prevede objekt na string */
toLocaleString()
var myDate = new Date();
document.write( myDate.toLocaleString());
// 24. února 2009 10:50:02
valueOf()
var number = new Number();
number = Number(100);
if (!isNaN(number))
document.write(number.valueOf()); // 100
hasOwnProperty(proName)
var theObj = { prom : 'bla' };
if ( theObj.hasOwnProperty )
{
document.write( "Has 'prom': " + theObj.hasOwnProperty( 'prom' ) + 'n' ); // true
document.write( "Has 'prom2': " + theObj.hasOwnProperty( 'prom2' ) + 'n' ); // false
}
isPrototypeOf(object2)
function fc(){
var reg = new RegExp();
return (RegExp.prototype.isPrototypeOf(reg)); // return true.
}
propertyIsEnumerable(proName)
var a = new Array("apple", "banana", "cactus");
document.write(a.propertyIsEnumerable(2)); // true
Získání IP adresy v PHP.
$serverIP=$_SERVER['REMOTE_ADDR'];
echo "document.write("Your IP address is: <b>" . $serverIP . "</b>")";
Funkce JavaScript pro práci s datumem a časem.
function msToTime(duration) {
var milliseconds = parseInt((duration % 1000) / 100),
seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
return hours + ":" + minutes + ":" + seconds + "." + milliseconds;
}
// console.log(msToTime(300000))
// output: 00:05:00.0
// get time difference between two dates in seconds
var startDate = new Date();
// Do your operations
var endDate = new Date();
var seconds = (endDate.getTime() - startDate.getTime()) / 1000;
var milliseconds = (endDate.getTime() - startDate.getTime());
[, OPTIONAL second param [, OPTIONAL ... param]]
static Date.now() // returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
parse(dateVal) // Date.parse('05 Dec 1998 00:12:00 GMT'); // return 912816720000
toDateString() // sunday 19.7.2020
toTimeString() // 20:15:37
getDate() // 1-31
getDay() // 0-6, 0 == Sunday
var now = new Date();
var dayOfWeekSundayIs7 = now.getDay() == 0)?7:now.getDay();
getFullYear() // 2020
getHours() // 0-23
getMilliseconds() // eg. 956
getMinutes() // 0-59
getMonth() // 0 january
getSeconds() // 0-59
getTime() // https://en.wikipedia.org/wiki/Unix_time
getTimezoneOffset() //returns the time zone difference, in minutes, from current locale
getYear() //does not return full years ("year 2000 problem"), it is no longer used and has been replaced by the getFullYear() method.
setDate(numDate) // 1-31 day of month
setHours(numHours[, numMin[, numSec[, numMilli]]]) // now.setHours(20, 21, 22); 20:21:22
setMilliseconds(numMilli) // 0-999
setMinutes(numMinutes[, numSeconds[, numMilli]]) // 0-59, 0-59, 0-999
setMonth(numMonth[, dateVal]) // 0-11
setSeconds(numSeconds[, numMilli]) 0-59 [, 0-999]
setYear(numYear) // not set full years ("year 2000 problem"), it is no longer used and has been replaced by the setFullYear() method.
setUTCDate() //
setUTCFullYear(2020) // 2020 sets the full year for a specified date according to universal time GMT
setUTCHours()
setUTCMilliseconds()
setUTCMinutes()
setUTCMonth()
setUTCSeconds()
toLocaleTimeString()
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
now.toLocaleDateString(undefined, options); //neděle 19. července 2020
// PDT Pacific Daylight Time (UTC -7)
// GMT ... SET GMT TIME +- ZONE ... new Date('December 31, 1974 23:59:30 GMT-3:00');
toGMTString() // DEPRECATED!!!! use toUTCString()
// Using UTC instead GMT!!!
var d = new Date("2020-07-15T00:00:00.000+07:00"); // UTC + 7
console.log(d.toISOString()); // "2020-07-14T17:00:00.000Z"
console.log(d.valueOf()); // 1594746000000
toISOString() // "2020-07-14T17:00:00.000Z"
toJSON() // "2020-07-14T17:00:00.000Z"
toSource() //This feature is obsolete!!!! Dont use!!!!
toString() // "Tue Jul 14 2020 19:00:00 GMT+0200 (Středoevropský letní čas)"
toUTCString() // "Tue, 14 Jul 2020 17:00:00 GMT"
valueOf() // 1594746000000
Toogle DIV javascript example code:
Jak skrýt, nebo zobrazit kontejner DIV:Nezapomeňte přiřadit DIVu ID, aby k němu bylo možno přistupovat pomocí getElementById a vše fungovalo i v jiných prohlížečích (Opera, Firefox, Google Chrome) a ne jen v Internet Exploreru.
<div id="idSomeDiv"> text div </div>
<input type="button" size="200" value="Skryj-zobraz"
onclick="var dH = document.getElementById('idSomeDiv');
if(dH.style.visibility == 'hidden') {
dH.style.visibility = 'visible';
} else {
dH.style.visibility = 'hidden';
}">
Tato funkce smaže původní soubor a vytvoří nový.
Parametry jsou cesta k souboru a pole řádků.
Nakonec nastaví mod přístupu k souboru.
Parametry jsou cesta k souboru a pole řádků.
Nakonec nastaví mod přístupu k souboru.
/**
* Tato funkce smaže původní soubor a vytvoří nový.
* Parametry jsou cesta k souboru a pole řádků.
* Nakonec nastaví mod přístupu k souboru.
*
* @param string $fname
* @param array $poleVstup
*/
function createNewFile($fname, $poleVstup)
{ // BEGIN function createNewFile
if(file_exists($fname))unlink($fname);
$fp = fopen($fname, "a");
if (flock($fp, LOCK_EX)) { // do an exclusive lock
foreach ($poleVstup as $key=>$value) {
fwrite($fp, $value); //
}
flock($fp, LOCK_UN); // release the lock
} else {
echo "Couldn't lock the file !";
}
fclose($fp);
chmod($fname, 0777); // set CHMOD
} // END function createNewFile
/**
* fopen() modes
*/
r Read
r+ Read and write, prepend
w Write, truncate
w+ Read and write, truncate
a Write, append
a+ Read and write, append
Od verze PHP 5.1.0 lze k uložení souboru se zámkem využít i funkci file_put_contents
přičemž flag bude mít hodnotu LOCK_EX
int file_put_contents ( string $filename , mixed $data [, int $flags = 0 [, resource $context ]] )
$file = "test.txt";
$content = "Some text which will put into file";
file_put_contents($file, $content, LOCK_EX);
Editace: 22.5.2020 - 22:31
Počet článků v kategorii: 77
Url:php-get-daylight-saving-time