Date problem: 1919/1010/20181818 03:15:16 PM

Asked

Viewed 50 times

-2

It’s all right but when it comes time to display or save the date in the bank, it’s getting so 1919/1010/20181818 03:15:16 PM... I don’t know what problem, or if I made a mistake somewhere. Does anyone know why this?? can see that the time is right but only happens on the date.


Page Settings(php):

(index)

$this->form_validation->set_rules('dateformat', lang('date_format'), 'required');
$this->form_validation->set_rules('timeformat', lang('time_format'), 'required');

($date)

'dateformat' => DEMO ? 'jS F Y' : $this->input->post('dateformat'),
                'timeformat' => DEMO ? 'h:i A' : $this->input->post('timeformat'),

footer:

<script type="text/javascript">

    var base_url = '<?=base_url();?>';

    var dateformat = '<?=$Settings->dateformat;?>', timeformat = '<?= $Settings->timeformat ?>';

    <?php unset($Settings->protocol, $Settings->smtp_host, $Settings->smtp_user, $Settings->smtp_pass, $Settings->smtp_port, $Settings->smtp_crypto, $Settings->mailpath, $Settings->timezone, $Settings->setting_id, $Settings->default_email, $Settings->version, $Settings->stripe, $Settings->stripe_secret_key, $Settings->stripe_publishable_key); ?>

    var Settings = <?= json_encode($Settings); ?>;
    $(window).load(function () {
        $('.mm_<?=$m?>').addClass('active');
        $('#<?=$m?>_<?=$v?>').addClass('active');
    });

</script>

Página all.js:

 $('.clock').click( function(e){
        e.preventDefault();
        return false;
    });
    function Now() { return new Date().getTime(); }
    var stamp = Math.floor(Now() / 1000);
    var time = date(dateformat+' '+timeformat, stamp);
    $('.clock').text(time);

    window.setInterval(function(){
        var stamp = Math.floor(Now() / 1000);
        var time = date(dateformat+' '+timeformat, stamp);
        $('.clock').text(time);
    }, 10000);

Header page:

<li class="hidden-xs hidden-sm"><a href="#" class="clock"></a></li>
  • Friend, welcome to the stack overflow forum. .

  • 1

    https://answall.com/help/mcve

  • Really. The problem misses that the parameter was being passed by the seat, dd/mm/Yyyy. I changed to d/m/Y.

2 answers

1


Good afternoon, I believe that at the time of showing off you must be using something like dd/mm/Yyyy H:i:s but in php the date formatting does not require more than one letter to identify which part of the date will be printed, try something like d/m/Y H:i:s to format it

  • The problem misses that the parameter was being passed by the seat, dd/mm/Yyyy. I changed to d/m/Y.

0

Try something similar to this example to work with dates.

// Definindo dados de teste aqui ou mandado via formulário.
$_POST["Data"] = "19/10/2018 16:30";
// Define a sua zona geografica.
date_default_timezone_set("America/Sao_Paulo");
// Gerar objeto DateTime.
$oData = new DateTime();
// Define a data para o objeto DateTime.
$_POST["Data"] = str_replace("/", "-", $_POST["Data"]);
$oData->setTimestamp(strtotime($_POST["Data"]));
// Mostra os dados
print($oData->format("d/m/Y H:i:s"));

Browser other questions tagged

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