我使用的是角度材质日期选择器https://material.angular.io/components/select/overview
但这只返回日期,而不返回当前时间: Mon May 28 2018 00:00:00 GMT+0530 (IST)
有没有办法也能得到当前的时间呢?
发布于 2018-05-28 17:51:13
angular材质现在不提供时间你需要手动从timeStamp获取时间,试试这个-
function getTimeFromDate(timestamp) {
let date = new Date(timestamp * 1000);
let hours = date.getHours();
let minutes = date.getMinutes();
let seconds = date.getSeconds();
return hours+":"+minutes+":"+seconds
}
let timeStamp = new Date("Mon May 28 2018 00:00:00 GMT+0530 (IST)")
console.log(getTimeFromDate(timeStamp));
发布于 2018-05-28 17:53:35
现在,材料日期选择器只提供当前日期(不包括当前时间),但在官方存储库中有一个开放的问题,所以我们可能会在不久的将来看到时间选择器。
发布于 2018-05-28 18:53:51
For Example currenttime = Mon May 28 2018 00:00:00 GMT+0530 (IST)
Currenttime is an example if u using current date means just use new Date()
//Sample function calling Method
Exacttime(){
this.functionName = this.diffhours(new(currenttime))
}
diffhours(currenttime){
var diff = new Date(currenttime);
diff .getHours(); // => 9
diff .getMinutes(); // => 30
diff .getSeconds(); // => 51
}
https://stackoverflow.com/questions/50563356
复制相似问题