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)
var 1_radian_to_degree = 180 / Math.PI; // 57,295779513082320876798154814105 degree
var 1_degree_to_radian = Math.PI / 180; // 0,01745329251994329576923690768489 radian
var 360_degree = 2 * Math.PI * 1_radian_to_degree;
var degree = 36.86;
var opposite = 600;
var hypotenuse = 1000;
var adjacent = 800;
// degree
// sin 45° == 0.7071067811865475;
var sin = Math.sin(45 * Math.PI / 180.0)
//sin == 0.7071067811865475;
// vypocet prepony (hypotenuse), kdyz zname
// protilehlou (opposite) a uhel (degree)
hypotenuse2 = opposite/ Math.sin(degree * Math.PI / 180.0);
// vypocet protilehle (opposite)
opposite2 = hypotenuse * Math.sin(degree * Math.PI / 180);
// vypocitat uhel alfa z velikosti protilehle a prepony ve stupnich (degree)
degree2 = Math.asin(opposite / hypotenuse)* (180/Math.PI); // 1rad
// velikost prepony pomoci prilehle (adjacent) strany a cos a uhlu v stupnich (degree)
hypotenuse3 = adjacent / Math.cos(degree * Math.PI / 180);
// velikost prilehle (adjacent) strany pomoci prepony a cos a uhlu v stupnich (degree)
adjacent2 = hypotenuse * Math.cos(degree * Math.PI / 180);
tan = Math.tan(degree * Math.PI/180); // 45° == 0.9999999999999
degree3 = Math.atan(opposite / adjacent)* (180/Math.PI); // 1rad
adjacent3 = opposite / Math.tan(degree * Math.PI / 180);
opposite3 = adjacent * Math.tan(degree * Math.PI / 180);
Jak vybrat kód mezi taky v Notepad++
How to select f.e. javascript tag contetn in Notepad++
- insert content between braces
- put caret behind the last bracket
- press Ctrl + left Alt + B or Ctrl + Shift + B to control the first brace
from parentheses to braces and check the multi-line box.
Then you can Ctrl-double-click on either brace to highlight everything in between.
How to select f.e. javascript tag contetn in Notepad++
- insert content between braces
- put caret behind the last bracket
- press Ctrl + left Alt + B or Ctrl + Shift + B to control the first brace
< script>
{
var bla = 0;
// bla bla ... long content
} // place caret/cursor behind the last brace { and press Ctrl + left Alt + B (Notepad++)
< /script>
At Settings->Preferences->Delimiter, change the delimiters
from parentheses to braces and check the multi-line box.
Then you can Ctrl-double-click on either brace to highlight everything in between.
// IF variable is not defined (or has a falsey value) THEN set it to an empty object.
// ELSE do nothing (technically speaking, variable gets assigned to itself)
var variable = variable || {} ;
function test(){
console.log(1);
}
// when called
test(); // 1
// or
var a = test;
a(); // 1
// or autocall if code executed
var test2 = function(){
console.log(2);
}
// test2 is undefined because the function test2 has no return value
// return string
function stringTest(param) {
return 'Hello ' + ' ' + param;
}
console.log(stringTest("Alice")); // Hello Alice
// return number
function numberTest(param) {
return 6 + param;
}
console.log(numberTest(5)); // 11
// or autocall if code executed
// function is like other variables
// parenthesis is for made groups or call functions.
// Immediately-Invoked Function Expression,
// or IIFE for short. It executes immediately after it’s created.
(function(){
// all your code here
var foo = function() {};
window.onload = foo;
// ...
})();
// foo is unreachable here (it’s undefined)
//////////////////////////////
// IIFE Immediately Invoked Funtion Expression
var greeting = function(name) {
return 'Hello ' + ' ' + name;
}('John');
console.log(greeting); // Hello John
console.log(typeof greeting); // string
console.log(greeting('Suzan')); // Uncaught TypeError: greeting is not a function
///////////////////////
var val = (function(){
var a = 0; // in the scope of this function
return function(x){
a += x;
return a;
};
})();
alert(val(10)); //10
alert(val(11)); //21
///////////////////////
// create the structure
var testHash = {
a : 1,
b : function(){
console.log(4);
},
c: function(param){
var num = param +5;
return num;
}
}
console.log(testHash.a); // 1
testHash.b(); // 4
testHash['b'](); // 4
testHash.c(7); // 12
/////////////////////////
// or function like class
function TestClass(n) {
this.some_property = n;
this.some_method = function() {
console.log(this.some_property);
};
}
var foo = new TestClass(3);
var bar = new TestClass(4);
foo.some_method(); // 3
bar.some_property += 2;
bar.some_method(); // 6
// console.log(some_property); // Uncaught ReferenceError: some_property is not defined
//////////////////////////
function Car(brand, year) {
return {
brand: brand,
year: year
}
}
var honda = Car("Honda", 1999);
console.log(honda.brand); // Honda
console.log(honda.year); // 1999
honda.brand = "Honda new Generation";
honda.year = 2021;
console.log(honda.brand); // Honda new Generation
console.log(honda.year); // 2021
var mazda = Car("Mazda",1987);
console.log(honda.brand); // Honda new Generation
console.log(mazda.brand); // Mazda
//////////////////////////////////////
// simplified code
var TEST_CLASS = TEST_CLASS || {};
TEST_CLASS.pokus = TEST_CLASS.pokus || (function() {
// -------------------------------------------------------------------------
// Private static variables and methods
// -------------------------------------------------------------------------
var privateStaticNumber = 5;
var privateStaticString = "My privateStaticString: ";
var privateStaticArray = [];
function privateStaticMethod(){
console.log('privateStaticMethod');
}
// CONSTRUCTOR CTOR
return function(config) {
// ----- private variables -----
var me = this,
isPaused = false;
this.privateStaticNumber = config.firstParam;
this.privateStaticString = privateStaticString + config.secondParam; // += produce: undefined I am from secondParam
this.privateStaticArray = config.thirtParam;
// ----- private methods -----
function getMode (mode, speed) {
// document.getElementById(mode).addEventListener('click', function () { snakeSpeed = speed; });
}
// ----- public variables -----
me.correct = 0;
me.wrong = 0;
// ----- public methods -----
me.setString = function(val) {
this.privateStaticString = val;
};
me.getString = function() {
return this.privateStaticString;
};
me.publicMethod = function(param){
console.log(param + ' from me.publicMethod()');
};
}; // end CTOR
})();
// end TEST_CLASS.pokus
var _me = _me || {};
var _me_test = new TEST_CLASS.pokus({firstParam:8, secondParam:" I am from secondParam", thirtParam:[1,3,9]});
// TEST_CLASS.pokus.privateStaticMethod(); // is not a function
// TEST_CLASS.pokus.publicMethod("Hola!"); // TEST_CLASS.pokus.publicMethod is not a function
// TEST_CLASS.publicMethod("Hola hej!"); // TEST_CLASS.publicMethod is not a function
// TEST_CLASS.pokus.publicMethod(" Hello!"); // is not a function
_me_test.publicMethod(" Hello!"); // Hello! from me.publicMethod()
console.log( _me_test.getString()); // My privateStaticString: I am from secondParam
console.log( _me_test.isPaused); // undefined
Date: 04.11.2020 - 23:14
Pokud často pracujete v PHP se soubory, tak se Vám může hodit
tato funkce, která vrací obsah souboru, jako string, narozdíl od funkce
file(), která vrací obsah souboru, jako pole řádků.
tato funkce, která vrací obsah souboru, jako string, narozdíl od funkce
file(), která vrací obsah souboru, jako pole řádků.
/**
* function return file content as string
* $filename is path to file
*/
function getContents($filename) {
if (function_exists('file_get_contents')) {
return file_get_contents($filename);
} else {
$fp = fopen($filename, 'r');
if (!$fp) {
echo ('Could not read contents <br/>');
return false;
}
return fread($fp, filesize($filename)); // return string
}
}
/**
* function file return file content as an array of rows
*/
$rows = file($filename);
/**
* 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
Jak změřit čas trvání vykonání nějaké funkce, nebo provedení části kódu v PHP
$start_time = microtime(true);
// do some work
$end_time = microtime(true);
// Calculate execution time
$execution_time = ($end_time - $start_time);
echo " Execution time = ".$execution_time." sec";
Date: 11.06.2020 - 09:14Editace: 22.5.2020 - 22:31
Počet článků v kategorii: 77
Url:php-get-daylight-saving-time