请在 javascript或jQuery :
中提供一些帮助如何当前日期和时间分钟?
我在该格式中有一个日期时间:'d/m/Y H:m'
(示例25/12/2016 22:35
)在输入中。如何获取并将其转换为分钟?并使它与当前日期时间有所不同
提前感谢您的帮助。我尝试过但没有任何作用
答案 0 :(得分: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);
答案 1 :(得分: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
感谢您的支持