cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the current date time of specific time zone in BPA

ayechan
Participant
0 Kudos
135

Hi everyone,

I would like to get the current date time of specific time zone (eg. AU time zone) in the BPA.

I used new Date() and it gets as GMT +0 time zone.

ayechan_0-1741946327349.png

How can I convert to AU time zone?

 

Best Regards,

Aye Chan

 

View Entire Topic
Sankara1
Product and Topic Expert
Product and Topic Expert

Hello AyeChan, 

To convert the current date and time to a specific time zone in SAP Build Process Automation, you can use JavaScript within a custom script or the Expression Editor. Here is a step-by-step guide:

  1. Get the Current Date and Time: Use new Date() to get the current date and time in GMT +0.

    var currentDate = new Date();
  2. Convert to Specific Time Zone: To convert the date and time to a specific time zone, you can use the toLocaleString method with the appropriate IANA time zone identifier. For example, to convert to Australian Western Standard Time (AWST):

    var options = { timeZone: 'Australia/Perth', hour12: false };
    var auDate = currentDate.toLocaleString('en-US', options);
  3. Example Script: Here is a complete example script to convert the current date and time to the Australian Western Standard Time (AWST):

    var currentDate = new Date();
    var options = { timeZone: 'Australia/Perth', hour12: false };
    var auDate = currentDate.toLocaleString('en-US', options);
    console.log(auDate); // Output the converted date and time

Using the Expression Editor

If you prefer using the Expression Editor in SAP Build Process Automation, you can enter the following expression:

new Date().toLocaleString('en-US', { timeZone: 'Australia/Perth', hour12: false })
ayechan
Participant
0 Kudos

Hi @Sankara1,

Thanks for your answer.