Showing posts with label Working With dates in Groovy Scripts. Show all posts
Showing posts with label Working With dates in Groovy Scripts. Show all posts

Tuesday, January 15, 2013



Working With Dates and format the date as per your requirements


1) the below code used to get the current timezones date and current date.
def Datecal = Calendar.getInstance()

log.info(Datecal.getTime())

def sYear = Datecal.get(Calendar.YEAR)

def sMonth = (Datecal.get(Calendar.MONTH)+1).next() // this prints next month

def sDay = Datecal.get(Calendar.DATE)

def sCurrDate = sDay+":"+sMonth+":"+sYear

log.info(sCurrDate)


and below code use to get required date format:-

import java.text.SimpleDateFormat

def sDate = new Date()

def sdf = new SimpleDateFormat("DD/MMM/YYYY")
log.info(sdf.format(sDate))