Format date Local


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

Função para formatar datas em formato UNIX


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. function format_date($unix, $format = '')
  4. {
  5. if ($unix == '' || ! is_numeric($unix))
  6. {
  7. $unix = strtotime($unix);
  8. }
  9.  
  10. if ( ! $format)
  11. {
  12. $format = 'd/m/Y H:i:s';
  13. }
  14.  
  15. return strstr($format, '%') !== FALSE
  16. ? ucfirst(strftime($format, $unix)) //or? strftime($format, $unix)
  17. : date($format, $unix);
  18. }
  19.  
  20. $agora = time();
  21. echo "Original: " . $agora . "<br />";
  22.  
  23. setlocale(LC_ALL, "pt_BR", "ptb");
  24. echo "Formatada: " . format_date($agora, 'hoje é %d de %B de %Y'). "<br />";
  25. echo "Formatada: " . format_date($agora). "<br />";
  26. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.