-2

Is there a way to parse an array of numbers to a date string in typescript?

This is how I would do it in C#:

    int[] date = { 2017, 10, 20 };

    public string convert(dynamic date)
    {
        return string.Format("{0}/{1}/{2}", date[1], date[2], date[0]);
    }

Any suggestions to do this in typescript/javascript?

2 Answers 2

2

The most similar to your C# code would probably be something like:

const date = [2017, 10, 20];

convert(date: number[]): string {
  return `${date[0]}/${date[1]}/${date[2]}`;
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can try something like:

let date = [2017, 10, 20]
const convert = function(d){
  return d.join('/')
}

or, for more versatile solutions you should check the Date built-in object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.