How to convert Unix timestamp to GMT formart

Hi All,

I have requirement that i get Unix TimeStamp from external system and i should convert it to GMT format how does pxCreateDateTime has in clipboard. Can any one know about this? Any OOTB function avalable. Please help me.

Ex: “createDtTime”: 1631023948012,

TIA.

Regards,

Vinay LAkka

@VinayLakka125

I am not aware of any OOTB way to directly convert from unix time stamp. If you don’t find a better way you can convert as below,

@addToDate("19700101T000000.000 GMT",@toInt(Param.UnixTime)/86400,(@toInt(Param.UnixTime)%(86400))/3600,((@toInt(Param.UnixTime)%(86400))%(3600))/60,((@toInt(Param.UnixTime)%(86400))%(3600))%(60))

In the below screenshot from expression builder, Param.UnixTime is the time you mentioned above in seconds. Your time is in milliseconds. I removed last three digits to convert it to seconds.

Please see below screenshot for online conversion of same unix time to GMT date. I tried with different date time values and its working.

@VinayLakka125 Create a new function (ex. UnixTimestampToPegaDateTime) with 2 parameters: timeUnix and timeZone with the following code. This will return the Pega date time format.

// Convert the string "timeUnix" to Date
Long d = Long.parseLong(timeUnix, 10);
Date d1 = new Date(d);

// Format to fit in the appropiate PEGA type
// timeZone can be "GMT-5"
return PRDateFormat.format(null, timeZone, PRDateFormat.PEGARULES_INTERNAL_DATETIME, d1);

If you want to get DATE instead of DATETIME use PRDateFormat.PEGARULES_INTERNAL_DATE.

Reference: https://community.pega.com/sites/default/files/help_v63sp1/Content/javadocs/com/pega/pegarules/pub/util/PRDateFormat.html#format(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.util.Date)

@ShyjuV69 Thank you above fix is working in single step. I will try to convert the same logic through function.

@Deivit I will try this function & get back you thank you so much.