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()


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


and below code use to get required date format:-

import java.text.SimpleDateFormat

def sDate = new Date()

def sdf = new SimpleDateFormat("DD/MMM/YYYY")

No comments:

Post a Comment