大家好,我正在尝试使用Dayjs()和format来获取指定格式的当前时间,但是每次我运行cypress测试时,它都会给我一个旧时间。代码如下:
const presentDateTime = dayjs().format('DD MMM YYYY HH:MM:ss');
cy.log(presentDateTime);
cy.spinner().should('not.exist');
engreenPo.firstNameLastName.then((text1) => {
engreenPo.dynamicPushHeader.should('contain', `${presentDateTime} by ${text1}`);
});我总是得到这样的输出
31 Aug 2021 13:08:11即使在我的本地系统中是13:43,但它在那个特定的时间被卡住了。我在应该断言中直接使用了带有format的Dayjs(),但它仍然是一样的。我不确定这些信息是否足以诊断问题。如果能帮上忙,我们将非常感激。谢谢
发布于 2021-08-31 11:56:02
大的MM代表月,小的mm代表分钟。
const presentDateTime = dayjs().format('DD MMM YYYY HH:mm:ss');
console.log(presentDateTime);
// Dynamic Example
setInterval(() =>
{
let presentDateTime = dayjs().format('DD MMM YYYY HH:mm:ss');
document.getElementById('time').innerText = presentDateTime;
},1000);<script src="https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.10.6/dayjs.min.js" integrity="sha512-bwD3VD/j6ypSSnyjuaURidZksoVx3L1RPvTkleC48SbHCZsemT3VKMD39KknPnH728LLXVMTisESIBOAb5/W0Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<body>
<div id="time"></div>
</body>
https://stackoverflow.com/questions/68998124
复制相似问题