JavaScript添加了最新的分钟

时间:2019-01-01 08:07:38

标签: javascript date

我试图将时间增加3分钟,但没有增加时间,而是表现为它们是两个字符串,并像字符串一样将它们加在一起。我在做什么错了?

var minutes = 3;
console.log(date.getTime() + (minutes * 60 * 1000));

4 个答案:

答案 0 :(得分:2)

要添加分钟,只需使用setMinutes方法:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <ajaxToolkit:Rating ID="Rating1" AutoPostBack="true" runat="server"
            StarCssClass="Star" WaitingStarCssClass="WaitingStar" EmptyStarCssClass="Star"
            FilledStarCssClass="FilledStar" OnChanged="OnRatingChanged" OnClick="Rating1_Click">
        </ajaxToolkit:Rating> 
        <asp:Label runat="server" ID="label3"></asp:Label>
        <asp:Label runat="server" ID="label4" Text="above"></asp:Label>
    </ContentTemplate>
</asp:UpdatePanel>

答案 1 :(得分:1)

应为new Date()

console.log(new Date().getTime() + 3*60*100)

答案 2 :(得分:0)

const now = Date.now();
const threeMinutesFromNow = now + 3 * 60 * 1000;
console.log(`now: ${new Date(now).toLocaleTimeString()}`);
console.log(`3m from now: ${new Date(threeMinutesFromNow).toLocaleTimeString()}`);

答案 3 :(得分:0)

这应该有帮助

var minutes = 3;

let newDate = new Date().getTime() + (minutes * 60 * 1000);
console.log(new Date(newDate).toLocaleTimeString())