Timeformat issue with using scheduled events in systemcontext

3
Dear all, For a client we archive certain log (auditlogging) objects everyday during a scheduled event. These auditlogging objects have timestamps and use System.CreatedDate. While debugging I can see these have the correct time also when displaying them in a regular datagrid. So far so good. Archiving these logs happens during a scheduled event which runs in a systemcontext - All archived logs are written in a log file (.txt). The problem we have is that all these logs are 2 hours behind in the .txt file(we are currently in GMT+2). While debugging, I learned (quite obvious now) that the session time is not shown in +2 (probably because of systemcontext) in the variables as it normally does , thus the time cannot be parsed to our local timezone. My question: Is there a way to print the correct date? Except implementing a timezone check during the archiving and depending on the timezone add an hour or maybe 2 hours? I've also checked variables like adding 'z' as in: MX Documentation formatDateTime($object/Date1,'EEE, d MMM yyyy HH:mm:ss Z') I look forward to your reply, Regards,
asked
2 answers
5

You can use the following Java action to convert any timestamp to a string representing that time in the timezone you require. Inputparameters:

  • DateTimeFormat (string - for example: 'yyyy-MM-dd'T'HH:mm:ss Z')
  • DateTimeToParse (DateTime)
  • TimeZone (string - see this list for examples like 'Europe/Amsterdam' https://garygregory.wordpress.com/2013/06/18/what-are-the-java-timezone-ids/)

Output Parameters is a string representation of your DateTime in a different timezone.

        // BEGIN USER CODE
    DateFormat requestedFormat = new SimpleDateFormat(DateTimeFormat);
    requestedFormat.setTimeZone(TimeZone.getTimeZone(TimeZoneParameter1));
    return requestedFormat.format(DateTimeToParse);
    // END USER CODE
answered
0

Hi Peter, try changing the Scheduled event time zone setting in your project settings. Can you check if this works?

answered