let offinsRecurs = [
moment("03-07-2018 8:00:00", "DD-MM-YYYY HH:mm:ss").recur().every(7).days(), //tuesday
moment("05-07-2018 15:00:00", "DD-MM-YYYY HH:mm:ss").recur().every(7).days(), //thursd
moment("06-07-2018 22:00:00", "DD-MM-YYYY HH:mm:ss").recur().every(7).days() //sat
];
let nextDatesOffin = offinsRecurs.map( recurDate => recurDate.fromDate(moment()).next(1) );
[ [ moment.utc("2018-07-10T8:00:00.000+00:00") ], // Next Tuesday
[ moment.utc("2018-07-12T15:00:00.000+00:00") ], // Next Thursday
[ moment.utc("2018-07-13T22:00:00.000+00:00") ] ] // Next Saturday
nextDatesOffin = offinsRecurs.map( recurDate => recurDate.fromDate(moment()).next(1)[0] );
let nextDateOffin = nextDatesOffin.reduce( (acc, elem) => Math.min(acc, elem), Infinity);
//moment(nextDateOffin)
//moment("2018-07-10T02:00:00.000")
//moment(nextDateOffin).fromNow()
//'in 3 days'
//console.log("Days:", nextDateOffin.days());
//console.log("H:", nextDateOffin.hours());
//console.log("M:", nextDateOffin.minutes());
let expiration = nextDateOffin
const now = moment();
const exp = moment(expiration);
console.log(exp.format());
days = exp.diff(now, 'days');
hours = exp.subtract(days, 'days').diff(now, 'hours');
minutes = exp.subtract(hours, 'hours').diff(now, 'minutes');
console.log(days, hours, minutes)
我试图从那一刻起获得剩余的时间。例如 1D2H43M 剩余。所有时间都必须是 PDT。写了所有这些,然后意识到它在错误的 TZ 中。所以不确定获得正确 TZ 的方法。这也给了我错误的余数。不确定是 TZ 还是这里的代码:
days = exp.diff(now, 'days');
hours = exp.subtract(days, 'days').diff(now, 'hours');
minutes = exp.subtract(hours, 'hours').diff(now, 'minutes');