如何使用 javascript 更具体地获取差异日期
how to get difference date using javascript more specific
大家好,我想使用 javascript 获取差异日期,在 php 我正在使用此脚本获取差异日期:
$tgl1 = date('Y-m-d');
$tgl2 = '2019-12-31';
$pecah1 = explode("-", $tgl1);
$date1 = $pecah1[2];
$month1 = $pecah1[1];
$year1 = $pecah1[0];
$pecah2 = explode("-", $tgl2);
$date2 = $pecah2[2];
$month2 = $pecah2[1];
$year2 = $pecah2[0];
$jd1 = GregorianToJD($month1, $date1, $year1);
$jd2 = GregorianToJD($month2, $date2, $year2);
$selisih = $jd2 - $jd1;
以及如何在 javascript
这可能有帮助:)
date1 = "2018-12-25"; //date1
date2 = "2019-01-01"; //date2
var one_day = 1000 * 60 * 60 * 24;
var x = date1.split("-");
var y = date2.split("-");
var new_date1 = new Date(x[0], (x[1] - 1), x[2]);
var new_date2 = new Date(y[0], (y[1] - 1), y[2]);
var month1 = x[1] - 1;
var month2 = y[1] - 1;
_Diff = Math.ceil((new_date2.getTime() - new_date1.getTime()) / (one_day));
console.log(_Diff);
大家好,我想使用 javascript 获取差异日期,在 php 我正在使用此脚本获取差异日期:
$tgl1 = date('Y-m-d');
$tgl2 = '2019-12-31';
$pecah1 = explode("-", $tgl1);
$date1 = $pecah1[2];
$month1 = $pecah1[1];
$year1 = $pecah1[0];
$pecah2 = explode("-", $tgl2);
$date2 = $pecah2[2];
$month2 = $pecah2[1];
$year2 = $pecah2[0];
$jd1 = GregorianToJD($month1, $date1, $year1);
$jd2 = GregorianToJD($month2, $date2, $year2);
$selisih = $jd2 - $jd1;
以及如何在 javascript
这可能有帮助:)
date1 = "2018-12-25"; //date1
date2 = "2019-01-01"; //date2
var one_day = 1000 * 60 * 60 * 24;
var x = date1.split("-");
var y = date2.split("-");
var new_date1 = new Date(x[0], (x[1] - 1), x[2]);
var new_date2 = new Date(y[0], (y[1] - 1), y[2]);
var month1 = x[1] - 1;
var month2 = y[1] - 1;
_Diff = Math.ceil((new_date2.getTime() - new_date1.getTime()) / (one_day));
console.log(_Diff);