-2

请我在javascript 或 jQuery方面需要一些帮助:

如何获取当前日期和时间到分钟

我有一个该格式的日期时间'd/m/Y H:m':(示例25/12/2016 22:35)在输入中。如何获取它并将其转换为分钟?并使其与当前日期时间有所不同

提前感谢您的帮助。我尝试了所有但没有任何效果

4

2 回答 2

0

要将当前日期和时间转换为分钟,您可以除以毫秒:

var theMinutes = new Date().getTime() / (1000 * 60);

要获取输入并将其转换为分钟,您可以使用 Date 对象,然后除以毫秒:

    var someDateTime = document.getElementById("someDateTime").value;
var someParts = someDateTime.split(" ");
var theDate = someParts[0];
var theTime = someParts[1];
var dateParts = theDate.split("/");
var timeParts = theTime.split(":");
var theDay = dateParts[0];
var theMonth = dateParts[1];
var theYear = dateParts[2];
var theHours = timeParts[0];
var theMinutes = timeParts[1];
var someDateTimeObject = new Date(theYear, theMonth, theDay, theHours, theMinutes, 0 );
var someDateTimeObjectMillis = someDateTimeObject.getTime();
var someDateTimeObjectMinutes = someDateTimeObjectMillis / (1000 * 60);
于 2015-11-01T03:48:58.327 回答
0

您好,谢谢您的所有回答

首先,我使用 php(以毫秒为单位)获取当前时间,然后将取件日期转换为毫秒,并以小时为单位获取它们之间的差异:促销(以分钟为单位)我通常得到 767 小时,我应该得到:47 小时和几分钟

 var startdate=document.getElementById('pickupdate').value; //03-11-2015 15:49


var someParts = startdate.split(" ");
var theDate = someParts[0];
var theTime = someParts[1];
var dateParts = theDate.split("-");
var timeParts = theTime.split(":");
var theDay = dateParts[0];
var theMonth = dateParts[1];
var theYear = dateParts[2];
var theHours = timeParts[0];
var theMinutes = timeParts[1];
var someDateTimeObject = new Date(theYear, theMonth, theDay, theHours, theMinutes, 0 );
var someDateTimeObjectMillis = someDateTimeObject.getTime();
//var someDateTimeObjectMinutes = someDateTimeObjectMillis / (1000 * 60);


alert(someDateTimeObjectMillis);
var maintenant = <?php echo(round(microtime(true) * 1000)); ?>;
alert(maintenant);
var diff = someDateTimeObjectMillis - maintenant;
alert(diff);

var promo = diff/(60 * 1000);
alert(promo); // 46079  

谢谢您的支持

于 2015-11-01T13:18:18.343 回答