Get current date time in UTC RFC 3339 format

An utility to format current datetime as a UTC string according to RFC 3339

A procedure to use in Seeburger BIC Mapping Designer
It will extend your library for string handling

  • Get current date / time with time zone (system default)
  • Format output
// -----------------------------
// Peter Lykkegaard, 30 okt 2024
// -----------------------------
// procedure getCurrentDateTimeUTC
// Parameters: None
//     Get current date / time
//     Format as String in UTC RFC 3339 format (eg 2022-10-13T23:37:18+02:00)
// Output
//    alphanumeric / String 
// Ref: https://medium.easyread.co/understanding-about-rfc-3339-for-datetime-formatting-in-software-engineering-940aa5d5f68a

#importJavaStart
    import java.time.format.DateTimeFormatter;
    import java.time.OffsetDateTime;
#importJavaEnd

local output$;

#javaStart
    String output;

    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX");
    OffsetDateTime now = OffsetDateTime.now();
    output = dtf.format(now);

    _StrVar_OUTPUT.setString(output);
#javaEnd

exitProc(output$);

Same but with inout parameters

  • Concatenate parameters
  • Parse string
  • Add system default time zone
  • Format output
// -----------------------------
// Peter Lykkegaard, 24 okt 2024
// -----------------------------
// procedure getCurrentDateTimeUTC
// Parameters: None
//     Parse given date / time from IDOC
//     Format expected is yyyyMMdd / HHmmss
//     Format as String in UTC RFC 3339 format (eg 2022-10-13T23:37:18+02:00)
// Params
//    Date$:    Alphanyumeric 
//    Time$:    Alphanyumeric
// Output
//    alphanumeric / String 
// Ref: https://medium.easyread.co/understanding-about-rfc-3339-for-datetime-formatting-in-software-engineering-940aa5d5f68a
 
#importJavaStart
    import java.time.*;
    import java.time.format.DateTimeFormatter;
    import java.time.OffsetDateTime;
#importJavaEnd

local output$;

#javaStart
    String documentDate = _StrVar_DATE.getString();
    String documentTime = _StrVar_TIME.getString();

    String output;

    String localDateTimePattern = "yyyyMMddHHmmss";
    String offsetDataTimePattern = "yyyy-MM-dd'T'HH:mm:ssXXX";

    String documentDateTime = documentDate + documentTime;

    DateTimeFormatter dtf;
    
    dtf = DateTimeFormatter.ofPattern(localDateTimePattern); 
    LocalDateTime dateTime = LocalDateTime.parse(documentDateTime, dtf);  
    
    ZoneId zoneId = ZoneId.systemDefault();
    OffsetDateTime odt = ZonedDateTime.of(dateTime, zoneId).toOffsetDateTime();
    
    dtf = DateTimeFormatter.ofPattern(offsetDataTimePattern);  
    output = dtf.format(odt);

    _StrVar_OUTPUT.setString(output);
#javaEnd
 
exitProc(output$);