How to Convert UTC time to PST time
In this usecase we will take input containing UTC time and we will convert this UTC time to PST time using scripting in Data process shape.
Let’s log into Boomi platform and follow some steps :
Steps:
1. Go to platform.boomi.com
2. Login by giving your valid credentials (Username and Password).
3. Home page will be displayed, now click on “Integration”.
4. Click on the “Create New” button.
5. Select “Process” and click on “Create”.
6. Click on “No Data” option and click on “Ok”.
7. Drag and drop one Set properties shape and add one dpp to store current date time.
8. Drag and drop a Data process shape and add the processing step as Custom Scripting.
9. Add the following script:
//Import the necessary libraries
import java.util.Properties;
import java.io.InputStream;
import com.boomi.execution.ExecutionUtil;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
//For giving a proper format to our output date
String DATE_FORMAT_1 = “yyyyMMdd HHmmss.SSS”;
DateTimeFormatter formatter_1 = DateTimeFormatter.ofPattern(DATE_FORMAT_1);
//Fetching the target and source ZoneIds
ZoneId fromTimeZone = ZoneId.of(“UTC”); //Source timezone
ZoneId toTimeZone = ZoneId.of(“America/Los_Angeles”); //Target timezone
//We took the UTC date time as a input through one DPP
String utcDateTime=ExecutionUtil.getDynamicProcessProperty(“DPP_DateTime”);
//LocalDateTime is an immutable date-time object that represents a date-time, often viewed as year-month-day-hour-minute-second. Other date and time fields, such as day-of-year, day-of-week and week-of-year, can also be accessed
LocalDateTime today = LocalDateTime.parse(utcDateTime);
// ZonedDateTime is an immutable representation of a date-time with a time-zone. This class stores all date and time fields, to a precision of nanoseconds, a time zone, with a zone offset used to handle ambiguous local date times.
ZonedDateTime currentUTCDateTime = today.atZone(fromTimeZone);
//Zoned date time at target timezone
ZonedDateTime currentPDTime = currentUTCDateTime.withZoneSameInstant(toTimeZone);
//Format date time
formatter_1.format(currentUTCDateTime);
String format_1 = formatter_1.format(currentPDTime);
//Store the converted date to another DPP.
ExecutionUtil.setDynamicProcessProperty(“DPP_CurrentDateTime”,format_1,false);
10. Click on “OK”.
11. Now you can add a Notify shape to log the new DPP value in the logs.
12. Add a Stop shape at the end. It will look like this:
13. Now try to Test the process with an atom with UTC time.
Here is of Zone Ids for some countries:
- ACT – Australia/Darwin
- AET – Australia/Sydney
- AGT – America/Argentina/Buenos_Aires
- ART – Africa/Cairo
- AST – America/Anchorage
- BET – America/Sao_Paulo
- BST – Asia/Dhaka
- CAT – Africa/Harare
- CNT – America/St_Johns
- CST – America/Chicago
- CTT – Asia/Shanghai
- EAT – Africa/Addis_Ababa
- ECT – Europe/Paris
- IET – America/Indiana/Indianapolis
- IST – Asia/Kolkata
- JST – Asia/Tokyo
- MIT – Pacific/Apia
- NET – Asia/Yerevan
- NST – Pacific/Auckland
- PLT – Asia/Karachi
- PNT – America/Phoenix
- PRT – America/Puerto_Rico
- PST – America/Los_Angeles
- SST – Pacific/Guadalcanal
- VST – Asia/Ho_Chi_Minh