JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-app='myApp' ng-controller="Controller">
{{ dateString }}
</div>
JavaScript
var app = angular.module('myApp', []);
app.controller('Controller', function ($scope,$filter) {
$scope.myValues = {};
$scope.myValues.start = new Date(2014, 10, 21, 07, 30, 50);
$scope.getDatePartials = function(portion) {
if(portion >= 10) {
return portion;
} else if(portion < 10) {
return "0"+portion;
} else {
alert("error");
}
}
$scope.formatDate = function(dateObj) {
var year = $scope.getDatePartials(dateObj.getFullYear());
var month = $scope.getDatePartials(dateObj.getMonth()+1);
var day = $scope.getDatePartials(dateObj.getDate());
var hour = $scope.getDatePartials(dateObj.getHours());
var minutes = $scope.getDatePartials(dateObj.getMinutes());
var seconds = $scope.getDatePartials(dateObj.getSeconds());
return year+"-"+month+"-"+day+" "+hour+":"+minutes+":"+seconds;
}
$scope.dateString = $scope.formatDate($scope.myValues.start);
});