显示当前日期小时和分钟

I am facing an issue in javascript dates. i want to do minutes and second from current date.

我的代码:

date = new Date();
currentdate = new Date();

newCurrent = GetFormattedDate(currentdate);

GetFormattedDate(date) {   
  hour =  ("0" + (date.getHours())).slice(-2);
  min =  ("0" + (date.getMinutes())).slice(-2);
  return  hour + ":" +  min;    //output 18:43
}

预期输出:

`18:00` //if minutes are 0 to 29 then show current hours reset the minutes again start with 0 like 18:00 

`18:30` //if minutes are 29 to 59 then show current hours reset the minutes again start with 30 like 18:30 

我该怎么办?有人帮我吗?

评论