Friday, March 19, 2010

Convert Date to String in groovy

import java.text.SimpleDateFormat

long lTime = new Date().time

String formattedDate = getUTCDateString(lTime)
println formattedDate

def getUTCDateString(long lTime)
{
Date lDate = new Date(lTime)
def cal = new GregorianCalendar(TimeZone.getTimeZone('UTC'))
cal.set(lDate[Calendar.YEAR],lDate[Calendar.MONTH],lDate[Calendar.DATE],lDate[Calendar.HOUR_OF_DAY],lDate[Calendar.MINUTE],lDate[Calendar.SECOND])
String formattedDate = new SimpleDateFormat("yyyy-mm-dd hh:mm").format(cal.time);
return formattedDate
}

1 comment:

  1. I have read your blog its very attractive and impressive. I like it your blog.

    Java Online Training Java EE Online Training Java EE Online Training Java 8 online training Core Java 8 online training

    Java Online Training from India Java Online Training from India Core Java Training Online Core Java Training Online Java Training InstitutesJava Training Institutes

    ReplyDelete