import java.util.TimeZone;
def tz = TimeZone.getTimeZone("Asia/Kuala_Lumpur")
def date = new Date();
def time = date.getTime()+tz.getOffset(date.getTime())
date.setTime(time)
In GAE:
Wrap the above in a method to bypass Reflections which GAE doesn't support
TimeZone.getAvailableIDs() also doesn't work in GAE because of Reflections
Correction, below works
public Date getDateWithTimeZone(Date date, String timeZone){
def tz = TimeZone.getTimeZone(timeZone);
def cal = Calendar.getInstance()
cal.setTimeInMillis( date.getTime() )
cal.setTimeZone( tz )
def offset = cal.get(Calendar.ZONE_OFFSET)
date.setTime( date.getTime()+offset )
return date;
}
No comments:
Post a Comment