How can I get the date and time in angular and send it to the comic book?

Asked

Viewed 897 times

0

I found that code: angular function to pick up date and time

I tested it and it works great. But I need to take this date and send it to the bank, along with other data. How can I do this?

My code is like this:

$scope.enviarMsg = function (mensagem) {

    function Time($scope){
        $scope.date = new Date();
    }
    var dte = Time($scope);

    var enviaMsg = {
        mensagem: mensagem,
        idUsuario: $window.localStorage.getItem('idUsuario'),
        idCep: $window.localStorage.getItem('idCep'),
        nome: $window.localStorage.getItem('nome'),
        date: dte
    }

    $http.post("http://www.vigilantescomunitarios.com/www/php/enviaMsgLogra.php", enviaMsg).success(function (data){

        console.log(data);
        pegaMsgsLogra();
        $scope.mensagem = {
          msg: ""
        }

    });
}

Console print Print do console

  • You are assigning the dte a date, this is not being sent in JSON?

  • Not @Techies, not being sent to JSON. See the image I posted.

  • I’m not seeing the picture.

  • I just put it.

  • 1

    Try to take this test: date: new Date(); instead of date: dte

  • It was, but in a strange way: "[day] => 2016-02-16T17:44:18.851Z"

  • This is the default, you will have to format the date in a way to send to BD or send it as Varchar

  • 1

    Thanks for the help, but I already got it with this site: http://momentjs.com/

Show 3 more comments

1 answer

2

That’s how it would work:

$scope.enviarMsg = function (mensagem) {
    var enviaMsg = {
        mensagem: mensagem,
        idUsuario: $window.localStorage.getItem('idUsuario'),
        idCep: $window.localStorage.getItem('idCep'),
        nome: $window.localStorage.getItem('nome'),
        date: new Date()
    }

    $http.post("http://www.vigilantescomunitarios.com/www/php/enviaMsgLogra.php", enviaMsg).success(function (data){

        console.log(data);
        pegaMsgsLogra();
        $scope.mensagem = {
          msg: ""
        }

    });
}

Browser other questions tagged

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