Question
Pegasystems Inc.
IN
Last activity: 4 Oct 2018 13:54 EDT
How to convert a DateTime property to unix timestamp format in Pega?
Hi
Is there a out of the box function to convert a DateTime property to unix timestamp format in Pega?
Thanks,
Sachin
**Moderation Team has archived post**
This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Pegasystems Inc.
IN
I am not sure if there is an OOTB function to achieve that but unix timestamp is simply java date time divided by 1000. So you can simply get java date using getDate method on Clipboard Page and then getTime on that divided by 100.
You can use @java to avoid java code and use it in simple Property Set.
E.x. @java("myStepPage.getDate(\"DateTimeProperty\").getTime() / 1000")
Let me know if this helps.
Pegasystems
US
Here's one way to look:
1) In an activity rule, start a property-set step with your DateTime property (fix your title on this discussion please, it says "data" !) as the right-hand side
2) On the left-hand side, click the gear so you can get into the expression editor
3) In the expression editor, you will see dropdown lists so you can peruse the available function libraries and their functions. Look at the libraries whose names pertain to date-time features.
/Eric
Pegasystems Inc.
IN
Thanks for replying Eric! I know that but I could not find an appropriate function for that.
Accepted Solution
Pegasystems Inc.
IN
I am not sure if there is an OOTB function to achieve that but unix timestamp is simply java date time divided by 1000. So you can simply get java date using getDate method on Clipboard Page and then getTime on that divided by 100.
You can use @java to avoid java code and use it in simple Property Set.
E.x. @java("myStepPage.getDate(\"DateTimeProperty\").getTime() / 1000")
Let me know if this helps.
Pegasystems Inc.
IN
Thanks Pankaj, it worked!!
Mfc Asset Management PCL
AE
First get the date object, then get the time in millisecond(millseconds after 01/01/1970 00:00:00), in the end, divide the milliseconds by 1000 to get the seconds, which is UNIX time.
e.g.
First get the date object, then get the time in millisecond(millseconds after 01/01/1970 00:00:00), in the end, divide the milliseconds by 1000 to get the seconds, which is UNIX time.
e.g.
String dateString = "Fri, 09 Nov 2012 23:40:18 GMT";
DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss z");
Date date = dateFormat.parse(dateString );
long unixTime = (long) date.getTime()/1000;
System.out.println(unixTime );//<- prints 1352504418
JPMC
IN
Is there any method/code to convert this unix time to Pega Date Time again