Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //endDate is 31.10.2018
- def format = messageService.getMessage(code: 'default.date.short.format')
- //--> dd.MM.yyyy for DE and MM/dd/yy for EN
- println("Use format: " + format)
- SimpleDateFormat sdf = new SimpleDateFormat(format);
- //set timezone (America/New_York)
- sdf.setTimeZone(TimeZone.getTimeZone(user.timeZoneID))
- //parse endDate
- Date parsedEndDate = sdf.parse(endDate)
- //create a calendar instance (e.g. America/New_York)
- Calendar calendarEnd = Calendar.getInstance(TimeZone.getTimeZone(user.timeZoneID));
- //set time
- calendarEnd.setTime(parsedEndDate);
- //set hour/minute automatically
- calendarEnd.set(Calendar.HOUR_OF_DAY, 23)
- calendarEnd.set(Calendar.MINUTE, 59)
- //at this point it should be 31.10.2018, 23:59 (german format, timezone America/New_York)
- //Convert to UTC before saving date in DB (MySQL)
- calendarEnd.setTimeZone(TimeZone.getTimeZone('UTC'))
- //save the date
- def obj = new Foo(date:calendarEnd).save(flush:true)
- <g:formatDate
- timeZone="${user.timeZoneID}"
- date="${fooInstance?.calendarEnd}"
- format="${message(code: 'default.date.format', default: 'MM/dd/yyyy, hh:mm a')}"/>
Add Comment
Please, Sign In to add comment