0

I need to convert a date to posix-format in order to use an API (WebSocket)

my Request: { "InstrumentId": 1, "FromDate": // POSIX-format date and time }

I'm not familiarized with Date manipulation. How can I get today's date and convert to posix-format?

0

2 Answers 2

-1

There is awesome library for date manipulations called moment.js. Just install it using

npm install --save moment

Code

my_Request: {
    "InstrumentId": 1,
    "FromDate": moment().format("MM/DD/YYYY H:M:S") // POSIX-format date and time
}

You can follow there documentation for more formats https://momentjs.com/docs/

Sign up to request clarification or add additional context in comments.

1 Comment

The default format for POSIX dates is %Y-%m-%d, e.g. 2018-03-02. A good answer should not rely on a library that isn't tagged or mentioned in the OP. Creating a POSIX format date is equivalent to creating an ISO 8601 format date, and there are already many, many questions and answers for that.
-1

You can use a library such as moment.js to do this easily. This allows you to convert a Javascript date object into any format you please

var date = new Date()
moment(date).format("MM/DD/YYYY H:mm:ss")

Comments