javascript - Transforming date which is in seconds to a 'day month year' date -


i have code works transform date in seconds day month year date. here is:

    var database = firebase.database();     database.ref(`trips/${userid}/trips/${tripid}/begindate`).once('value').then(photossnap => {     var tripbegindateseconds = photossnap.val();     var tripbegindatefull = new date(0); // 0 there key, sets date epoch     tripbegindatefull.setutcseconds(tripbegindateseconds);     var tripbeginmonth = tripbegindatefull.getutcmonth() + 1; //months 1-12     var tripbeginday = tripbegindatefull.getutcdate();     var tripbeginyear = tripbegindatefull.getutcfullyear();     tripbegindate = tripbeginday + "/" + tripbeginmonth + "/" + tripbeginyear;     $('#tripbegindate').html(tripbegindate);      }); 

i trying implement angularjs code. retrieving data firebase database, , displaying them angularjs. here js code retrieve data:

var app = angular.module('test', []);  app.controller('mainctrl', function($scope) {     var database = firebase.database();     database.ref(`trips/${userid}/trips`).once('value')    .then(photossnap => {   var trips = []; photossnap.foreach((trip) => { trips.push({ tripkey: trip.key, tripname: trip.val().name, tripphotourl: trip.val().photourl, tripbegindate: trip.val().begindate, tripenddate: trip.val().enddate }); });  $scope.repeatdata = trips;  // apply immediatly, otherwise doesn't see changes      $scope.$apply();  // returns array in console check values      console.log($scope); }).catch(err => alert(err));       }); 

here tripbegindate , tripenddate variables contain dates in seconds. these variables i'm trying transform date day month year. don't know how implement code js script make work.

since have function code functionality, wrap code function this:

function convertdate(dateinseconds) {     var tripbegindateseconds = dateinseconds;     var tripbegindatefull = new date(0); // 0 there key, sets date epoch     tripbegindatefull.setutcseconds(tripbegindateseconds);     var tripbeginmonth = tripbegindatefull.getutcmonth() + 1; //months 1-12     var tripbeginday = tripbegindatefull.getutcdate();     var tripbeginyear = tripbegindatefull.getutcfullyear();     tripbegindate = tripbeginday + "/" + tripbeginmonth + "/" + tripbeginyear;     return tripbegindate; } 

and use on dates this:

tripbegindate: this.convertdate(trip.val().begindate), tripenddate: this.convertdate(trip.val().enddate) 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -