I have a calendar which is initialized this way:
startDate: moment().subtract('month', 1).startOf('month'),
endDate: moment()
}, function(start, end) { // on date change - save it and retrieve later
// start is the start date
// end is the end date
}
I want to be able to save and restore the start and end dates. As you can see startDate and endDate must be in "moment". I can store it to a cookie or on the server - that doesn't matter.
My question is how to serialize the dates and then restore?
I have a calendar which is initialized this way:
startDate: moment().subtract('month', 1).startOf('month'),
endDate: moment()
}, function(start, end) { // on date change - save it and retrieve later
// start is the start date
// end is the end date
}
I want to be able to save and restore the start and end dates. As you can see startDate and endDate must be in "moment". I can store it to a cookie or on the server - that doesn't matter.
My question is how to serialize the dates and then restore?
Share Improve this question asked May 21, 2015 at 3:21 user266003user2660031 Answer
Reset to default 17Best solution is to store as milliseconds since epoch...
var ms = moment().valueOf();
...then you can easily restore by passing that value into the moment constructor...
var dt = moment(ms);