Vi hoje no blog do Leandro Vieira uma função para exibição de datas por extenso em PHP.
como já tinha feito algo parecido antes gostaria de mostrar pra vocês, não é uma função, ou melhor, usa funções nativas do PHP.
No PHP existe uma função que seleciona o idioma que você quer usar em seu programa, essa função é a
setlocale().
Ex:
O primeiro parâmetro “LC_TIME”, define a categoria das funções que serão afetadas, nesse caso, afetara as funções de data.
O segundo parâmetro definimos o idioma usado. Esse parâmetro dependa da disponibilidade do idioma instalado no sistema, varia de sistema pra sistema, veja mais sobre no manual da função.
A outra função necessária pra nosso codigo é a strftime(), ela que formatara a data da forma que agente quer.
note que o primeiro parametro é onde configuramos a formatação da data, pode encontra mais a respeito no manual da função, e segundo especificamos o timestamp, se deixamos em branco retornara a data corrente.
E finalmente
Retornara…
segunda, 01 de junho de 1992
Solução bem elegante, mas nem tão eficiente, pois depende da disponibilidade do idioma estar instalar no sistema.
22 Responses
Leandro Vieira Pinho
April 21st, 2007 at 5:09 am
1Olá Alisson,
Obrigado pelo link.
Excelente e função e muito elegante de fato, mas como você falou, dependo da disponibilidade do sistema.
Primeiramente, eu pensei nisso, e sinceramente aqui no meu PC não consegui algo produtivo com o setlocale, motivo que me levou a criar a função.
Mesmo assim, valeu aí.
Um abraço.
kakaroto
April 21st, 2007 at 12:43 pm
2eu iar postar no post do leandro mais esta dando erro
la no blog ,eu tambem achei estranho aquela funcao gigante
pq ele e da antiga no imasters
aqui fiz e assim :
setlocale(LC_ALL, ‘portuguese’);
echo strftime (” %A %d %e %B de %Y”, time());
/*
sexta-feira 20 abril 2007 */
ta no manual do php e tudo o set localle
kakaroto
http://www.obsidian.com.br
kakaroto
April 23rd, 2007 at 1:58 pm
3ops ….
essa linha eu errei
e assim foi mal
echo strftime(“%A, %d de %B de %Y”, time());
um abraço
kakaroto
Alisson Patrício
April 23rd, 2007 at 5:22 pm
4Leandro, eu tambem não tive sucesso na primeira tentativa, mas depois de varias tentivas consegui fazer funcionar.
A maior dificuldade foi em encontrar o “locale” da lingua portuguesa em ambiente windows, em linux é so rodar na shell “locale -a” que ele retorna os “locales” disponiveis no sistema.
Kakaroto, tambem não conseguir comentar no blog do Leandro por isso acabei fazendo este post aqui, e não se preocupe errar é humano e faz parte da aprendizagem.
Um abraço.
Sávio
May 7th, 2008 at 2:35 pm
5A dica do kakaroto ta certa!!! 😛
para português basta colocar:
setlocale(LC_ALL, ‘portuguese’);
Dica de grande ajuda, valeu!!!
Vinicius
December 22nd, 2008 at 12:44 pm
6Ótimo…
tinha uma função gigante pra traduzir isso rs
agora resolvo em duas linhas
Shari Pacas
October 22nd, 2010 at 5:28 am
7Please visit my site.
Regards
NEX-5N
November 17th, 2011 at 9:13 am
8Eu realmente queria desenvolver uma pequena observação de dizer obrigado a você por algumas das recomendações incrível que você está escrevendo neste site. O meu olhar se tem internet considerável no final foi reconhecido com sugestões brilhantes para trocar com os meus convidados. Eu afirmaria que os visitantes do site que na verdade são bastante sorte de existir em uma comunidade maravilhosa, com tantas pessoas de destaque com princípios muito benéfico. Sinto-me muito feliz por ter utilizado a sua página web inteira e esperamos muitas vezes mais brilhante de ler aqui. Obrigado mais uma vez para todos os detalhes.
birthday party designs
December 6th, 2012 at 4:53 am
9This is really interesting, You’re a very skilled blogger. I’ve joined your feed and look forward to seeking more of your excellent post.
Also, I’ve shared your website in my social networks!
elmo 1st birthday supplies
December 22nd, 2012 at 2:36 am
10Wow, awesome blog layout! How long have you been blogging
for? you make blogging look easy. The overall look of your web
site is great, let alone the content!
my.opera.com
February 28th, 2013 at 10:15 am
11I do not know if it’s just me or if perhaps everyone else experiencing issues with your site. It looks like some of the text within your posts are running off the screen. Can someone else please provide feedback and let me know if this is happening to them as well? This might be a issue with my internet browser because I’ve had this happen before.
Appreciate it
Best Juicers
April 21st, 2013 at 2:10 am
12It’s awesome for me to have a website, which is beneficial in favor of my knowledge. thanks admin
ads
April 21st, 2013 at 3:38 am
13What’s Happening i’m new to this, I stumbled upon this I have found It positively useful and it has helped me
out loads. I hope to give a contribution & assist
different customers like its helped me. Good job.
Updated Photos
November 26th, 2013 at 7:51 am
14Hi, There’s no doubt that your website could be having web browser compatibility issues. Whenever I look at your site in Safari, it looks fine however, when opening in IE, it has some overlapping issues. I just wanted to provide you with a quick heads up! Apart from that, wonderful blog!
louis vuitton wallet men
January 7th, 2014 at 9:36 am
15If you’re uncertain in the path your beard grows, do not shave to get a few times and observe the angles that the beard grows into. Various parts of the encounter can develop in diverse angles. This indicates you are going to ought to move your razor about and shave in diverse directions in an effort to shave using the grain.
louis vuitton wallet men http://www.b2mundi.com/louis-vuitton-wallets/louis-vuitton-wallet-men.html
Monster Energy snapbacks wholesale
January 30th, 2014 at 6:36 am
16Hello to all, for the reason that I am genuinely eager of reading this webpage抯 post to be updated on a regular basis. It carries nice material.
Monster Energy snapbacks wholesale http://www.insta-moldwest.com/privacy/hats.cfm?p=Monster-Energy-snapbacks-wholesale.html
replica louis vuitton
February 10th, 2014 at 12:11 am
177 Greatest Beauty Guidelines for Gorgeous Skin
replica louis vuitton http://www.inmarinhousecleaning.com/replica-louis-vuitton/
Child Porn
June 2nd, 2014 at 4:15 pm
18Child Porn…
Função para exibir data por extenso, em PHP | Alisson Patrício…
bit.ly
September 10th, 2014 at 2:14 am
19Wow that was odd. I just wrote an incredibly
long comment but after I clicked submit my comment didn’t show
up. Grrrr… well I’m not writing all that over again. Anyhow, just wanted to say superb blog!
kitchen design ideas gallery
September 27th, 2014 at 12:11 pm
20Yes! Finally something about home owner.
friendship tattoos
October 21st, 2014 at 7:20 am
21It’s great that you are getting thoughts from this article as well as from our
dialogue made at this time.
Bing
March 13th, 2016 at 6:18 pm
22Yes! Finally something about reef sandals bottle opener.
RSS feed for comments on this post · TrackBack URI
Leave a reply
Categories
2
Tags
Recent Posts
Recent Comments
Alisson Patrício is proudly powered by WordPress - BloggingPro theme by: Design Disease