Converting epoch to date string

Converting epoch to date string

Hi,

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


    Zoho Desk Resources

    • Desk Community Learning Series


    • Digest


    • Functions


    • Meetups


    • Kbase


    • Resources


    • Glossary


    • Desk Marketplace


    • MVP Corner


    • Word of the Day


      Zoho CRM Plus Resources

        Zoho Books Resources


          Zoho Subscriptions Resources

            Zoho Projects Resources


              Zoho Sprints Resources


                Zoho Orchestly Resources


                  Zoho Creator Resources


                    Zoho WorkDrive Resources



                      Zoho Campaigns Resources

                        Zoho CRM Resources

                        • CRM Community Learning Series

                          CRM Community Learning Series


                        • Tips

                          Tips

                        • Functions

                          Functions

                        • Meetups

                          Meetups

                        • Kbase

                          Kbase

                        • Resources

                          Resources

                        • Digest

                          Digest

                        • CRM Marketplace

                          CRM Marketplace

                        • MVP Corner

                          MVP Corner




                          Zoho Writer Writer

                          Get Started. Write Away!

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

                            Zoho CRM コンテンツ




                              ご検討中の方