Convert pzLoadTime into standard Pega Date Time format

It seems curious to me that pzLoadTime (eg



March 5, 2025 at 5:40:55 PM GMT)

doesn’t follow the standard date time format like pxRequestorStart or pyUserLoginTime.



20250305T174144.236 GMT





while there are many functions to use the pega standard time stamp, I didn’t see much OOTB to convert the pzLoadTime into something that could be passed to @DateTimeDifference, since I have a long lived node level page that I would like to run logic on under certain conditions related to the load time.

Has anyone generated code to already convert this property?

@Peter G :warning: This answer is by a GenAI-powered tool. All generated answers require validation against the provided reference.

" here’s a solution you can implement to convert the pzLoadTime format (e.g., “March 5, 2025 at 5:40:55 PM GMT”) to the standard Pega DateTime format (e.g., “20250305T174144.236 GMT”):

/* 
 * Function to convert pzLoadTime format to standard Pega DateTime format
 * Input: String in format "March 5, 2025 at 5:40:55 PM GMT"
 * Output: String in format "20250305T174144.236 GMT" 
 */
function convertPzLoadTimeToStandardDateTime(pzLoadTimeString) {
  // Create a JavaScript Date object from the pzLoadTime string
  var dateObj = new Date(pzLoadTimeString);
  
  // Extract date components
  var year = dateObj.getUTCFullYear();
  var month = (dateObj.getUTCMonth() + 1).toString().padStart(2, '0'); // Month is 0-indexed
  var day = dateObj.getUTCDate().toString().padStart(2, '0');
  
  // Extract time components
  var hours = dateObj.getUTCHours().toString().padStart(2, '0');
  var minutes = dateObj.getUTCMinutes().toString().padStart(2, '0');
  var seconds = dateObj.getUTCSeconds().toString().padStart(2, '0');
  
  // Default milliseconds to .000 if not available
  var milliseconds = "000";
  
  // Construct the Pega DateTime format
  var pegaDateTime = year + month + day + "T" + hours + minutes + seconds + "." + milliseconds + " GMT";
  
  return pegaDateTime;
}

You can implement this JavaScript function in an HTML rule or within a custom function in Pega. To use it:

  1. Add this function to your page or section where you need the conversion
  2. Call it with your pzLoadTime value
  3. Use the returned string with @DateTimeDifference

For example:

// Get the pzLoadTime value
var pzLoadTimeValue = pega.rules.getPropertyValue("pzLoadTime");

 
// Convert to standard format
var standardFormatDateTime = convertPzLoadTimeToStandardDateTime(pzLoadTimeValue);

 
// Now you can use it with @DateTimeDifference
var timeDifference = @DateTimeDifference(standardFormatDateTime, @CurrentDateTime, "SECONDS");

If you need to implement this in Pega rules rather than JavaScript, here’s an alternative approach using Pega’s built-in functions:

// In an activity or data transform
when (true)
{
  // Step 1: Parse the pzLoadTime string into a Java Date object
  java.text.SimpleDateFormat inputFormat = new java.text.SimpleDateFormat("MMMM d, yyyy 'at' h:mm:ss a z", java.util.Locale.ENGLISH);
  java.util.Date dateObj = inputFormat.parse(tools.getParamValue("pzLoadTime"));
  
  // Step 2: Format the Date object in Pega's standard DateTime format
  java.text.SimpleDateFormat pegaFormat = new java.text.SimpleDateFormat("yyyyMMdd'T'HHmmss.SSS 'GMT'");
  pegaFormat.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));
  String standardDateTime = pegaFormat.format(dateObj);
  
  // Now standardDateTime can be used with @DateTimeDifference
}

"

References:
Date properties
Functions supported for optimization

@MarijeSchillern Thanks Marije,

We decided to use our own property so we would be able to use standard functions and avoid use of a pz property.