get UTC date/time for mendix object

1
How do I retrieve the UTC timezone for a mendix object out of the mendix database in a java action. If i have object x and want to get attribute date I do: x.getDate() - this returns date but 1 hour off the database
asked
1 answers
5

A java.util.Date is in UTC by definition as this object is nothing but a wrapper around the unix epoch value for a date/time. Only when you convert it to a string (for example using a SimpleDateFormat) or put it in a Calendar, a timezone can be applied.

Consider this example:

    Date date = new Date();
    System.out.println(date);   //prints Thu May 05 17:14:37 CEST 2011 with the default toString() of the Date class
    SimpleDateFormat utcDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    utcDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    System.out.println(utcDateFormat.format(date)); //prints 2011-05-05 15:14:37
answered