How to get time and use it as variable

How I use time as variable in Katalon Studio?

like robot framework
${time} = Get Time
when I run “sign up” test case, I can input account ${time}, so it is unique.
It will not repeat when I run “sign up” test case every time

Thanks.

Try this…

//ADD to import header in test case

import java.text.SimpleDateFormat

//Google search for SimpleDateFormat for other formats that can be used

String CDATE = new SimpleDateFormat(“MM-dd-yyyy”).format(Calendar.getInstance().getTime());

String CTIME = new SimpleDateFormat(“HH:mma”).format(Calendar.getInstance().getTime());

println('CurrentDate: ’ + CDATE)

println('CurrentTime: ’ + CTIME)

2 Likes

Dave Evers said:

Try this…

//ADD to import header in test case

import java.text.SimpleDateFormat

//Google search for SimpleDateFormat for other formats that can be used

String CDATE = new SimpleDateFormat(“MM-dd-yyyy”).format(Calendar.getInstance().getTime());

String CTIME = new SimpleDateFormat(“HH:mma”).format(Calendar.getInstance().getTime());

println('CurrentDate: ’ + CDATE)

println('CurrentTime: ’ + CTIME)

Thanks Dave,
CDATE works fine. :smiley:
But how about past date and future date ?

I have beenn using below to get Current date/time in my test case

Date today = new Date()

String todaysDate = today.format(‘dd/MM/yyyy HH:mm’)

2 Likes

It’s work with me and very easy to understand.
thank you, prashant

Would you happen to know how to get date from an element and match it to today’s date to pass a test?

basically,

  1. I’m creating a value and it has the creation date
  2. I want to fetch that creation date (element) and match it to today’s date to pass