Date function in Portuguese

2

I have this code

<table class="table table-hover table-bordered table-condensed  lista-clientes table table-striped table-bordered table-condensed">
        <thead>
           <tr>
              <th>
                 <center>IP Address</center>
              </th>
              <th>
                 <center>Banned By</center>
              </th>
              <th>
                 <center>Reason</center>
              </th>
              <th>
                 <center>Banned On</center>
              </th>
              <th>
                 <center>Banned Until</center>
              </th>
           </tr>
        </thead>
        <tbody>
           <?php 
           date_default_timezone_set('UTC');
           while($row = $retval->fetch_assoc()) { 
              if($row['banner'] == null) {
                 $row['banner'] = 'Console';
              }
              // <<-----------------Ban Date Converter------------>> //
              $timeEpoch = $row['time'];
              $timeConvert = $timeEpoch / 1000;
              $timeResult = date('F j, Y, g:i a', $timeConvert);
              // <<-----------------Expiration Time Converter------------>> //
              $expiresEpoch = $row['expires'];
              $expiresConvert = $expiresEpoch / 1000;
              $expiresResult = date('F j, Y, g:i a', $expiresConvert);
              ?>
           <tr>
              <td>
                 <?php
                    $ip = $row['ip'];

                    $array = explode(".", $ip);
                    $numbers = $array[0] . "." . $array[1] . "." . $array[2];
                    $numbers .= ".";

                    for($i = 0; $i < strlen($array[3]); $i++) {
                      $numbers .= "*";
                    }

                    echo $numbers;
                    ?>
              </td>
              <td><?php echo $row['banner'];?></td>
              <td style="width: 30%;"><?php echo $row['reason'];?></td>
              <td><?php echo $timeResult;?></td>
              <td><?php if($row['expires'] == 0) {
                 echo 'ETERNO';
                 } else {
                 echo $expiresResult; }?></td>
           </tr>
           <?php }
              $conn->close();
              echo "</tbody></table>";
              ?>

But I want to leave the date, schedules etc ... In Portuguese but I can not ... It's just getting English. Could someone help me?

    
asked by anonymous 20.02.2018 / 04:33

1 answer

1

In order to use dates with "pt-BR" (Brazil) or "pt-PT" (Portugal) setlocale and strftime .

The difference between date and strftime (in addition to the parameters), is that strftime works with the specified location, while date ignores those values.

In function setlocale , we can decide whether to apply the location in all fields or just date, money, time etc. To apply only with dates, use setlocale(LC_TIME, "<Idioma>");

<?php

/* Localização */
setlocale(LC_ALL, "pt-BR");

/* Ignora a localização */
echo date("F j, Y, g:i a").PHP_EOL;

/* Aplica a data com localização */
echo strftime("%B %d, %G, %I:%M %p");

Your code should look like this:

<?php

date_default_timezone_set('UTC');
setlocale(LC_ALL, "pt-BR");

while($row = $retval->fetch_assoc()) { 
    if($row['banner'] == null) {
    $row['banner'] = 'Console';
}

// <<-----------------Ban Date Converter------------>> //
$timeEpoch = $row['time'];
$timeConvert = $timeEpoch / 1000;
$timeResult = strftime("%B %d, %G, %I:%M %p", $timeConvert);

// <<-----------------Expiration Time Converter------------>> //
$expiresEpoch = $row['expires'];
$expiresConvert = $expiresEpoch / 1000;
$expiresResult =  strftime("%B %d, %G, %I:%M %p", $expiresConvert);
?>
  

For other parameters of the stftime function, just go to documentation

    
20.02.2018 / 05:18