PHP Datum formát - date function
PHP formát datumu
Datum a čas v PHP
echo date('l jS of F Y h:i:s A');
// vypise neco podobneho: Saturday 21st of February 2009 11:38:59 AM
mktime()
strtotime()
time()
Y 4 číselný rok 2009
y 2 číselný rok 02
F celý měsíc February
M skratka měs Feb
m Měsíc (0 na počátku ) 01 do 12
n Měsíc 1 do 12
D skratka dne Sat
l dlouhý nazev dne Saturday
d Den (0 na počátku) 01 do 31
j Den pořadí 1 do 31
h 12 Hodina(0 na počátku) 01 do 12
g 12 Hodina 1 do 12
H 24 Hodina(0 na počátku) 00 do 23
G 24 Hodina 0 do 23
i Minuty (0 na počátku) 00 do 59
s Sekundy (0 na počátku) 00 do 59
w Den týdne(0 neděle) 0 do 6
z Den v roce 0 do 365
W Týden v roce 1 do 53
t Dnů v měsíci 28 do 31
a am nebo pm
A AM nebo PM
B Swatch Internet Time 000 do 999
S Ordinal Suffix st, nd, td, th
T Timezone of machine GMT
Z Timezone offset (seconds)
O Difference to GMT (hours)+0200
I Letní čas 1 nebo 0
L Přestupný rok 1 nebo 0
U Sekund v epoše od 1. January 1970.
c ISO 8601 (PHP 5)
r RFC 2822
Číslo týdne pro 1. leden může vrátit
53 pokud týden bude začínat předešlým rokem.
date("W", mktime(0, 0, 0, 12, 28, $year))
vždy dá správné číslo týdne v roce
$year.
date_default_timezone_set('Europe/London');
$datetime = date_create('2009-09-03 17:32:20');
echo date_format($datetime, DATE_ATOM);
77LW NO topic_id
AD
Další témata ....(Topics)
Pokud vytvářite novou instanci nějakého objektu, musíte použít klíčové slovo new
class myClass {
private $var = 'Who I am? ';
function __construct($val){
$this->var .= $val;
}
function fc()
{
print 'Hello from myClass <br>';
print $this->var;
}
}
$myInstance = new myClass('I am a variable');
$myInstance->fc(); // Hello from myClass <br>Who I am? I am a variable
Tohle jsou některé metody objektu document
clear
createDocument
createDocumentFragment
createElement
createEvent
createEventObject
createRange
createTextNode
getElementById
/* nejpouzivanejsi metoda objektu document, ktera
ziska handle elementu dle jeho id*/
getElementByTagName
var e = document.getElementById('list');
e= e.getElementsByTagName('span');
i=0;
while(i < e.length){
e[i].style.color = "green";
}
write
document.write("some text");
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);
Tthis code works in all previous versions of browsers
Pause code by alert
Set timeout
Pause code by alert
var n = 1;
alert(n);
n = 5;
alert(n);
Set timeout
var n = 5;
// wait 5 second / do next code
// next code put into function and call this function by setTimeout
setTimeout("nextCodeFc (n)",5000); // wait for 5000 millisecond == 5 second and execute
// how put string as parameter into setTimeout
var str = "Hello string parameter!";
setTimeout('nextCodeFc("str")',3000); // produce "str"
setTimeout('nextCodeFc("'+str+'")',3000); // produce "Hello string parameter!"
setTimeout("nextCodeFc(str)",3000); // produce Hello string parameter!
function nextCodeFc (n){
// do work .........
alert(n);
}
List of usefull JavaSript functions and constans
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;
parseInt("10.33") // returns 10 string to integer
parseFloat("10.33") // returns 10.33 string to float
// change sign
var a = -1;
a = a * -1; // +1
// random sign
a *= Math.floor(Math.random()*2) == 1 ? 1 : -1;
var who_is = 58;
var type = (typeof who_is); // number
Math.E // natural logarithms, e, approximately 2.718281828459045
Math.LN10 // natural logarithm of 10, approximately 2.302585092994046
Math.LN2 // natural logarithm of 2, approximately 0.6931471805599453
Math.PI // approximately 3.141592653589793
Math.SQRT1_2 // square root of 1/2 which is approximately 0.7071067811865476
Math.SQRT2 // square root of 2, approximately 1.4142135623730951
Math.pow(4, 2) = 16 // 4 x 4 ... base 4 to the exponent 2 power
Math.abs(-5) absolute value of a number // return 5
Math.tan(degrees * Math.PI / 180) // get tangent from degrees
Math.tan(degree * Math.PI / 180)*adjacent = opposite
opposite / Math.tan(degree * Math.PI / 180) = adjacent
Math.acos(adjacent / hypotenuse) // angle of a right-angle triangle in radians
Math.atan(opposite / adjacent) // angle of a right-angle triangle in radians
var adjacent = Math.cos(radian) * hypotenuse; // leng of adjacent side
// find the point on a circle if you know the circle´s radius
var x = Math.cos(pointAngleInRadiansFromCentreOfCircle) * radius;
var y = Math.sin(pointAngleInRadiansFromCentreOfCircle) * radius;
Math.cbrt(64) // cube root of a number 4 (4 x 4 x 4)
Math.exp(xNumber) // returns e<sup>xNumber</sup> ... e == Math.E
Math.ceil() // always rounds a number up to the next largest integer
Math.ceil(1.001) // 2
Math.floor() // returns largest integer less than or equal to a given number
Math.floor(5.85) = 5
Math.floor(-5.15) = -6
const arrayA = [2, 3, 1];
Math.min(...arrayA) = 1;
Math.max(1, 3, 2) = 3;
Math.random() // returns 0.000.... - 0.99999999999
Math.random() * 3 // returns 0.000 - 2.99999999999
Math.round() // returns value of a number rounded to the nearest integer.
Math.round(0.9) // 1
Math.round(5.5) // 6
Math.round(5.05) // 5
Math.floor(Math.random() * 3) // returns 0, 1, 2
Date: 14.06.2020 - 08:38Editace: 22.5.2020 - 22:24
Počet článků v kategorii: 77
Url:php-datum-format