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
}
Developer, Java Evangelist, extensively worked on Java, GWT, Flex, RIA technologies with enterprise frameworks. I have a privilege to conduct lot of Training/Coaching in Java Technologies, and to connect with real people.
Showing posts with label Dates in groovy. Show all posts
Showing posts with label Dates in groovy. Show all posts
Friday, March 19, 2010
Convert Date to String in groovy
Labels:
Dates in groovy,
Groovy goodness
Sunday, December 6, 2009
Converting String to Date in Groovy
Recently I was looking for a simple way to convert a String object to a Date format in groovy..
below is the example.
In groovy, its just a one liner to make this happen
String timeStampStr = "2009-12-01T12:36:22Z"
def strDate = new Date().parse("yyyy-MM-dd'T'HH:mm:ss'Z'",timeStampStr)
println strDate.
below is the example.
In groovy, its just a one liner to make this happen
String timeStampStr = "2009-12-01T12:36:22Z"
def strDate = new Date().parse("yyyy-MM-dd'T'HH:mm:ss'Z'",timeStampStr)
println strDate.
Labels:
Dates in groovy,
parsing dates in groovy
Subscribe to:
Posts (Atom)