Formatar Data e Hora Portugues


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**
  2. * Esta função retorna uma data escrita da seguinte maneira:
  3. * Exemplo: Terça-feira, 17 de Abril de 2007
  4. * @author Leandro Vieira Pinho [http://leandro.w3invent.com.br]
  5. * @param string $strDate data a ser analizada; por exemplo: 2007-04-17 15:10:59
  6. * @return string
  7. */
  8. function formata_data_extenso($strDate)
  9. {
  10. // Array com os dia da semana em português;
  11. $arrDaysOfWeek = array(’Domingo’,'Segunda-feira’,'Terça-feira’,'Quarta-feira’,'Quinta-feira’,'Sexta-feira’,'Sábado’);
  12. // Array com os meses do ano em português;
  13. $arrMonthsOfYear = array(1 => ‘Janeiro’,'Fevereiro’,'Março’,'Abril’,'Maio’,'Junho’,'Julho’,'Agosto’,'Setembro’,'Outubro’,'Novembro’,'Dezembro’);
  14. // Descobre o dia da semana
  15. $intDayOfWeek = date(’w',strtotime($strDate));
  16. // Descobre o dia do mês
  17. $intDayOfMonth = date(’d',strtotime($strDate));
  18. // Descobre o mês
  19. $intMonthOfYear = date(’n',strtotime($strDate));
  20. // Descobre o ano
  21. $intYear = date(’Y',strtotime($strDate));
  22. //Retorna também a hora (Adicionado por Rafael (ebalaio.com)
  23. $intHour = substr($strDate,10,20);
  24. // Formato a ser retornado
  25. return $arrDaysOfWeek[$intDayOfWeek] . ‘, ‘ . $intDayOfMonth . ‘ de ‘ . $arrMonthsOfYear[$intMonthOfYear] . ‘ de ‘ . $intYear . ‘ às ‘.$intHour;
  26. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.