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.
Friday, March 19, 2010
Convert Date to String in groovy
Labels:
Dates in groovy,
Groovy goodness
Tuesday, March 9, 2010
Check if String is Number
String nbrStr = "30239023902390239023902323"
boolean b = nbrStr.isNumber()
assert b == true
boolean b = nbrStr.isNumber()
assert b == true
Labels:
Groovy goodness,
numbers in groovy
Groovy String to Integer
Converting a String to Number
String nbrStr = "100"
int i = nbrStr.toInteger()
assert i==100
String nbrStr = "100"
int i = nbrStr.toInteger()
assert i==100
Labels:
Groovy goodness,
String to Integer
Subscribe to:
Posts (Atom)