I am currently working on saving various data, including the current date, in a JSON file stored in LocalStorage. While I have been successful in saving the data, the date is saved in the ISO 8601 format:
[{"date":"2014-10-13T17:55:32.953Z"}]
This format complicates things for me when I need to retrieve and filter the data later on. Is there a way to change the date format (such as converting it to DD-MM-YYYY) before parsing it into the JSON file?
Below is 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!");
}
}
Any suggestions or advice you can provide would be greatly appreciated!