Hamza
Hamza

Reputation: 213

Dayjs is not picking the current system time

Hello everyone I am trying to use Dayjs() with format to get the current time with the specified format but every time I run my cypress test it gives me an old time. Here is the code below:

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}`);
            });

And I always get this output

31 Aug 2021 13:08:11

Even though in my local system it's 13:43 but it is stuck at that particular time. I directly used Dayjs() with format in the should assertion but still its the same. I am not sure if this information is enough to diagnose the problem. Help would be highly appreciated. Thank you

Upvotes: 0

Views: 1088

Answers (1)

Dhana D.
Dhana D.

Reputation: 1720

The big MM stands for Month, the small mm stands for minutes.

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>

Upvotes: 1

Related Questions