Data si Timpul

Stefanescu Mihai 2 years ago PHP
Acest articol face parte din cursul Toate lectiile PHP. Te poti inscrie la acest curs aici!

Datele sunt lucruri cu care lucram in fiecare zi incat ni se pare foarte usor, iar PHP-ul vine cu cateva instrumente care ne ajuta foarte mult la manipularea datelor.

Time Stamp si functia time():

Functia time() din PHP ne ofera data si timpul curente. Nu necesita niciun argument si returneaza un integer.

Numarul intreg returnat de aceasta functie reprezinta numarul de secunde trecute din 1 Ianuarie 1970.

<?php
echo time();
?>

Ne va da urmatorul rezultat:

1420804132

Acest tip de informatie este greu de inteles, dar PHP-ul ne ofera cateva unelte foarte bune de convertit timestamp-ul intr-un format usor de inteles.

Convertirea Time Stamp-ului cu getdate():

Functia getdate() accepta un parametru (time stamp-ul) si returneaza un array asociativ ce contine informatii despre data. Daca nu-i dai nici-un parametru va returna data curenta.

In urmatorul tabel sunt informatiile oferite de getdate() in acel array asociativ:

Cheie Descriere Exemplu
seconds Secunde trecute(0-59) 45
minutes Minute trecute(0-59) 27
hours Ora(0-23) 18
mday Ziua din luna(1-31) 7
wday Ziua din saptamana(0-6) 3
mon Luna din an (1-12) 9
year Anul 2007
yday Ziua din an(0-356) 249
weekday Ziua din saptamana Friday
 month Luna din an April
 0  timestamp 1420804132

Acum, ai control complet asupra datei si a timpului. Puteti formata data in orice format va doriti:

<?php
$date_array = getdate();
foreach ( $date_array as $key => $val ){
   echo "$key = $val<br />";
}

$data  = "Data de azi: ";
$data .= $date_array[mday] . "/";
$data .= $date_array[mon] . "/";
$data .= $date_array[year];

print $data;
?>

Rezultatul:

seconds = 27
minutes = 25
hours = 11
mday = 12
wday = 6
mon = 5
year = 2007
yday = 131
weekday = Saturday
month = May
0 = 1178994327
Data de azi: 12/5/2007

Convertiere Time Stamp cu date():

Functia date() returneaza un string cu data formatata intr-un anumit mod. Cu aceasta functie aveti control total asupra formatului datei.

date(format, timestamp);

Puteti folosi functia date() fara a mai da un timestamp si aceasta va folosi timestamp-ul curent. Orice alt caracter pasat in informatiile de formatare va fi inclus in valoarea returnata.

Urmatorul tabel contine toate informatiile necesare la formatare:

Format Descriere Exemplu
a ‘am’ sau ‘pm’ in litere mici pm
A ‘AM’ sau ‘PM’ in litere mari PM
d Ziua din luna, numar fara 0 in fata 15
D Ziua saptamanii (3 litere) Thu
F Numele lunii January
h Ora (Format de 12 ore cu 0 in fata) 12
H Ora (Format de 24 ore cu 0 in fata) 22
g Ora (Format de 12 ore – fara 0 in fata) 12
G Ora (Format de 24 ore – fara 0 in fata) 22
i Minute (0-59) 23
j Ziua din luna(fara 0 in fata) 20
l (L mic) Ziua din saptamana. Thursday
L An bisect 1 sau 0
m  Luna din an (numar cu zero in fata) 04
M Luna din an (3 litere) Jan
r Data in format FC 2822  Thu, 21 Dec 2007 18:07:09 +0200
n Luna din an(numar fara 0 in fata)  4
s Secunda 34
U timestamp  1420806736
y An 02
Y An 2007
z  Ziua din an (0-356) 314

Exemplu:

<?php
print date("m/d/y G.i:s<br>", time());
print "Azi este ";
print date("j of F Y, \a\\t g.i a", time());
?>

Rezultatul:

01/20/00 13.27:55
Azi este 20 of January 2000, at 1.27 pm

 

Programator de ~8 ani, am lucrat la proiecte din mai multe industrstrii, de la eCommerce la telecomunicatii la automatizari. In acest timp am folosi diferite tehnologii, de la PHP, MySQL, PostgreSql, RabbitMq, Redis, Memcached si altele.


Get in touch
Pentru nelamuriri, dubii, comentarii si chestii de pe suflet ne putem auzi pe Discord, Reddit sau poti deschide o discutie noua pe forum

texas gambling 2023 # 4 months ago DraftKings invariably enters your mind when you talk of trusted online gambling enterprise sites.
Mgwhtc # 1 month ago cheap tricor 160mg <a href="https://fenoficor.com/">tricor 200mg brand</a> buy fenofibrate pill
Eupwjl # 1 month ago order ketotifen sale <a href="https://flixitorp.shop/">ketotifen medication</a> order tofranil generic
Vpinuw # 1 month ago buy minoxytop online cheap <a href="https://abcelemax.shop/">flomax 0.4mg generic</a> ed pills comparison
Yuzios # 1 month ago buy precose 50mg online <a href="https://tofobose.shop/">where can i buy precose</a> brand fulvicin 250mg
Jwnhsd # 4 weeks ago buy generic aspirin over the counter <a href="https://levquinon.shop/">purchase zovirax online cheap</a> order imiquad generic
Magdalena # 3 weeks ago I believe that is among the most important info for me. And i am happy reading your article. However want to observation on some basic issues, The web site style is great, the articles is in reality excellent : D. Just right process, cheers
Lmvzmy # 3 weeks ago buy dydrogesterone <a href="https://janozin.shop/">order forxiga 10mg online</a> cheap jardiance
Denise # 3 weeks ago Hi, I want to subscribe for this weblog to take latest updates, thus where can i do it please help out.
Okmmem # 3 weeks ago brand florinef <a href="https://acipolax.shop/">how to get dulcolax without a prescription</a> imodium 2mg ca
Kqikcq # 2 weeks ago order etodolac 600mg generic <a href="https://colotazol.com/">colospa brand</a> order cilostazol 100mg pills
Shnxhu # 2 weeks ago prasugrel 10 mg pill <a href="https://thoramine.shop/">order dramamine online cheap</a> tolterodine where to buy
mycelex online beschikbaar zonder recept # 2 weeks ago Excellent, what a blog it is! This webpage presents valuable information to us, keep it up.
Sgxhox # 2 weeks ago ferrous usa <a href="https://betaotec.com/">buy betapace for sale</a> sotalol cost
Ondumq # 2 weeks ago pyridostigmine medication <a href="https://mestien.com/">pyridostigmine generic</a> purchase rizatriptan generic
precio del misoprost en una farmacia # 2 weeks ago Currently it looks like BlogEngine is the best blogging platform available right now. (from what I've read) Is that what you are using on your blog?
precio del misoprost en una farmacia # 2 weeks ago Currently it looks like BlogEngine is the best blogging platform available right now. (from what I've read) Is that what you are using on your blog?
?Ist es möglich # 2 weeks ago Do you mind if I quote a few of your posts as long as I provide credit and sources back to your webpage? My website is in the exact same area of interest as yours and my users would truly benefit from some of the information you provide here. Please let me know if this ok with you. Appreciate it!
achat de betoquin en Italie # 1 week ago I'm curious to find out what blog platform you are using? I'm experiencing some small security problems with my latest blog and I would like to find something more secure. Do you have any recommendations?
Ncujlj # 1 week ago vasotec buy online <a href="https://casosin.shop/">buy doxazosin 2mg for sale</a> buy lactulose medication
Lpzoaf # 1 week ago zovirax oral <a href="https://aexeloda.shop/">exelon 6mg over the counter</a> purchase rivastigmine generic
aravida ohne Rezept erforderlich # 1 week ago Good answers in return of this issue with firm arguments and telling everything concerning that.
aankoop van enpresse als slaappil # 1 week ago Hello my friend! I wish to say that this post is amazing, great written and include approximately all vital infos. I would like to peer more posts like this .
Tpmifq # 6 days ago telmisartan 80mg usa <a href="https://molnenil.shop/">how to get molnunat without a prescription</a> order molnunat 200 mg pills
amoval te koop in Europa # 6 days ago I visited several sites but the audio quality for audio songs current at this web site is genuinely fabulous.
veramix verkrijgbaar bij Nederlandse apotheken # 5 days ago Ahaa, its fastidious conversation regarding this piece of writing here at this website, I have read all that, so now me also commenting at this place.
astelin zonder medisch voorschrift in Marokko # 5 days ago Hey there! This post could not be written any better! Reading this post reminds me of my previous room mate! He always kept chatting about this. I will forward this article to him. Fairly certain he will have a good read. Thanks for sharing!
Aexgtn # 4 days ago cheap cenforce 50mg <a href="https://chlodinir.com/">purchase chloroquine for sale</a> aralen 250mg cheap
nessuna prescrizione necessaria per domanion # 4 days ago Hi, the whole thing is going sound here and ofcourse every one is sharing information, that's in fact fine, keep up writing.
dymista disponibile senza prescrizione medica a Verona # 3 days ago Hello there! I could have sworn I've visited this blog before but after browsing through many of the posts I realized it's new to me. Nonetheless, I'm certainly pleased I came across it and I'll be bookmarking it and checking back often!
¿se puede obtener clomifene sin prescripción médica? # 1 day ago It's wonderful that you are getting thoughts from this paragraph as well as from our discussion made at this time.
Bjopsr # 22 hours ago cefdinir 300mg generic <a href="https://glurazol.com/">buy glycomet 1000mg online</a> lansoprazole pills
zakup albenza online w Warszawie # 12 hours ago Thank you a bunch for sharing this with all of us you really recognise what you're speaking about! Bookmarked. Kindly also visit my web site =). We could have a hyperlink change arrangement between us
Club-ul este dedicat membrilor si ofera access la mai multe zone ale website-ului.
Login Register

🔖 Bookmarks
✨ Pentru a sustine aceasta comunitate am sa te rog sa te autentifici sau sa te inregistrezi!

🌪️ Discord
Back to top
Folosim cookie-uri pentru a oferi functionalitatile critice ale aplicatiei Invata-Programare. Folosim cookie-uri si pentru a analiza traficul, pentru care e nevoie de consimtamantul dvs. explicit.