Accessing Current Time & Different Timezone

1a. Accessing Current Time in Cypress:

We have to install the npm moment dependencies in order to access the Cypress.moment syntax.

Reference: https://momentjs.com/ arrow-up-right

Pre-requirements: 1. Install:

$ npm install moment --save-dev
circle-info

Save in /cypress/support/index.js:

hello.sh
 Cypress.moment.locale('en');

Examples: Let's get the Current time using Cypress.moment()

Get Current Time in AM/PM

const nowTime = Cypress.moment().format('LTS')
cy.log('Current Timezone', nowTime)

Response: 1:47:33 PM Get Current Time in 24hrs

const now24Time = Cypress.moment().format('H:m:s')
cy.log('Current Timezone in 24hrs', now24Time)

Response: 13:47:33

Get Current time in 24hours format & Adding 10 minutes

const addTenMintues24hrs = Cypress.moment().add(10, 'minutes').format('H:m:s')

cy.log('Current Timezone in 24hrs format & add 10 Mints', addTenMintues24hrs)

Get Current time in am/pm & Adding 10 minutes

Get the Current date & Add 10 days

1b) Accessing Time Zones in Cypress: Additional to the above dependencies, We have to install the npm moment-timezone dependencies in order to work with moment.tz() Pre-requirements: 1. Install:

circle-info

Save in /cypress/support/index.js:

Examples: Let's get time from the specified Timezone using Cypress.moment() Reference: https://momentjs.com/timezone/ arrow-up-right Get CEST Timezone in Am/PM Here we are referring to CEST (Europe/Stockholm) Timezone

Response: 6:47:33 AM Get CEST Timezone in 24hrs

Response:06:47:33 Get time in 24 hours format & Adding 10 minutes

Response:06:57:33 TimeZone Parse and display dates: Reference: https://momentjs.com/timezone/ arrow-up-rightTime display Formats: Reference: https://momentjs.com/docs/#/displaying/arrow-up-right

Last updated