I am having date in my site, and I am using dates using daterangepicker and moment js. Now I am new to all these things & one of the variable setting up date is as
moment().subtract(29, 'days')
whose console.log
results into 1492930351644
,
similarly moment()
result to 1495435951644
.
Now on manual change by the user I want, to update this values but however I don't know how to make use of it. I have used jQuery event as below
$('#dateRange').on('apply.daterangepicker', function(ev, picker) {
var startDate_1 = moment.utc(startDateCal).format('LL');
var endDate_1 = moment.utc(endDateCal).format('LL');
dates.setData('startDateCal',startDate_1);
dates.setData('endDateCal',endDate_1);
console.log(" changed start date "+dates.getData('startDateCal'));
console.log(" changed end date "+dates.getData('endDateCal'));
});
so when I change and select the date as today from view calender I am get into the above change event but my output would be
changed start date May 21, 2017
changed end date May 22, 2017
Here I want an output or date format similar to 1492930351644
as shown by moment().subtract(29, 'days')
but I don't know how would I be able to achieve that. Any help?
try this change .
format('LL')
to.format('x')
i.eYou want to save the unix ms timestamp format as a
data-
attribute. You are doing it right, you just have to use theformat
date function like this:Or when you read the data back, you should create a moment object out of it and use
valueOf
to get the number format:It seems like you are currently using a fixed
startDateCal
andendDateCal
. I suggest to you to use the picker attribute in the callback function to get the actual date from the picker itself, like this: