Converting epoch to date string

Converting epoch to date string


I've been working on Flow and getting jobs from orchestly lately. I had big trouble (and time) for the conversion, but found out the way to go ! This is not so obvious.

1. fetch a job from Orchestly, and get the JSON as returned data.
2. create a deluge script which will handle the list of fields (list jobsfields)
3. I only take care of DATA and DATE_TIME fiel format here.

  1. for each  job_field in job_fields
  2. {
  3.     if((job_field.get("field_type_value").lower() == "date" || job_field.get("field_type_value").lower() == "date_time") && job_field.get("value") != "")
  4.     {
  5. // "value": 1614553200000
  6. // "data_type_value": "BIGINT"
  7.         lineResult = job_field.get("value").toLong().toTime().toString("dd-MM-yyy");
  8. // lineResult is "01-03-2021" (1st March 2021)
  9.     }
  10.     else
  11.     {
  12.         lineResult = job_field.get("value");
  13.     }
  14. }

FOR EACH parses each the fields in the list

IF checks for the DATE and DATE_TIME fields only

We convert the data. In the JSON the value is a number : "value": 1614553200000 (EPOCH time if you are wondering)

Line 7: This is were I missed completely the point for hours. I presupposed 1614553200000 (in the JSON) was a BIGINT.
I tried without success
  1. lineResult = job_field.get("value").toString("dd-MM-yyy");
It is not a BIGINT! It first needs to be converted to Long, then to Time...

You get then lineResult = "01-03-2021" as expected for 1st March 2021.

Little note : I used yyy and not yyyy. In the documentation, toString() uses yyy (3 y) to display full year (4 digits), which is different for toTime() / toDate() who use yyyy (4 y) for year mapping !

Hope this helps

    • Sticky Posts

    • Function #41: Sync Associated Subforms!

      Welcome back everyone! The last custom function showed how to update a Contact with Product details from it's Related list in Deals. This week, let's look at a function that lets you update subform records in two modules simultaneously when one of them is updated. Business scenario Let's look at how subform helps in an education institution that has deployed Zoho CRM. National Public School, Austin (made up, of course!) has set up Zoho CRM and it follows the same relationship pattern of "Students",

      Zoho SalesIQ Resources

            Zoho TeamInbox Resources

              Zoho DataPrep Resources

                  Zoho CRM Plus Resources

                    Zoho Books Resources

                      Zoho Subscriptions Resources

                        Zoho Desk Resources

                          Zoho Projects Resources

                            Zoho Sprints Resources

                              Zoho Orchestly Resources

                                Zoho Creator Resources

                                  Zoho WorkDrive Resources

                                      Zoho Campaigns Resources

                                        Zoho CRM Resources

                                                    Design. Discuss. Deliver.

                                                    Create visually engaging stories with Zoho Show.

                                                    Get Started Now

                                                      Zoho Show Resources

                                                        Zoho Writer Writer

                                                        Get Started. Write Away!

                                                        Writer is a powerful online word processor, designed for collaborative work.