Gravatar for d.kumar.chittimilla@accenture.com

Question by dkchittimilla, Apr 25, 2017 3:23 PM

Date field value - Parsing in javascript

Hi,

We have a computed field for date and after indexing, the value for date field is coming like below.

Ex: 1423803600000

We are not sure which format this is, it is showing 13 characters. We would like to parse this format to dd/MM/YYYY using javascript. Could you please let us know how to format this string.

Thanks.

Gravatar for gminero@coveo.com

Comment by gminero, Apr 25, 2017 3:37 PM

fyi - that number is a Unix Timestamp, you can view its "human readable date" here: https://www.epochconverter.com/

2 Replies
Gravatar for slangevin@coveo.com

Answer by Simon, Apr 25, 2017 3:35 PM

Hi,

Here is how to build a Date Computed field: https://developers.coveo.com/x/agDvAQ

The most important element is the Return Type.

    public string ReturnType
    {
        get {
            return "datetime";
        }
        set {
        }
    }
Gravatar for flguillemette@coveo.com

Answer by François Lachance-Guillemette, Apr 25, 2017 3:41 PM

You should be able to parse it in JavaScript using `new Date(timestamp)` and converting this date into any format you want.

The framework also provides a helper function date if you are trying to render this field in an underscore template.

Ask a question