Date function in Portuguese

Asked

Viewed 713 times

1

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>";
              ?>

However I want to leave the date, schedules etc... In Portuguese however I’m not getting... It’s just getting into English. Could someone help me ?

Show 3 more comments

1 answer

1

To use dates with location on "en BR" (Brazil) or "en PT" (Portugal), the use of two functions: setlocale and strftime.

The difference between date and strftime (beyond the parameters), is that strftime works with the indicated location, while date ignores these values.

In function setlocale, we can decide if we want 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);
?>

To know other function parameters stftime, just access to documentation

  • I tried and I couldn’t... nothing comes up when I put this code

  • @zlDeath updated code

  • http://prntscr.com/ihhggd still does not show anything...

  • @zlDeath if possible put your updated code on Pastebin.com and post the link here

  • https://hastebin.com/araluruvuw.xml

  • could see ?

  • Check whether strftime is returning false. If so, it is necessary to modify the parameters such as %I, %M etc. Check the value of $time also and test with the example var_dump(strftime("%A", 1519061884014 / 1000));

  • Could edit in my code and send me in hastebin ?

  • @zlDeath is complicated because I do not know the return of SQL and some options setlocale changes depending on the server (windows and linux), it is also necessary to check in the documentation. For example: This code works for me: https://imgur.com/a/aDXpA

  • But could not try to fix ? But I think it is returning false because nothing appears

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.