I'm trying to save the current date (among other data) in a JSON file in LocalStorage. So far I get to save the data, but JSON will save it in the ISO 8601 format:
[{"date":"2014-10-13T17:55:32.953Z"}]
It kinda makes it hard for me later when I want to call the data back and filter it and so on. Is there some way to change the date() format (To DD-MM-YYYY, for instance) before parsing into the JSON file?
Here's my current code:
$scope.dateHeader = new Date();
$scope.recordlist = extractRecordJSONFromLocalStorage();
$scope.addRecord = function () {
$scope.recordlist.push({ date: $scope.dateHeader});
jsonToRecordLocalStorage($scope.recordlist);
};
function extractRecordJSONFromLocalStorage() {
return JSON.parse(localStorage.getItem("records")) || [
];
}
function jsonToRecordLocalStorage(recordlist) {
var jsonRecordlist = angular.toJson(recordlist);
if (jsonRecordlist != 'null') {
localStorage.setItem("records", jsonRecordlist);
} else {
alert("Invalid JSON!");
}
}
Thanks in advance for any advice you can trow in my direction!