Reputation: 348
I need to send a date(ISO) to server from my file(React-native). But backend(node.js) accepts a date in string format.
Date in UI => 2021-02-10T13:01:00.000Z.
Expected Date format in backend is => "2021-02-10T13:01:00.000Z"
I tried date.toString() method. It changes the format of date like Wed Feb 03 2021 16:46:56 GMT+0530 (India Standard Time) this.
Is there any other JS method to change the typeOf date.
Thanks in Advance.
Upvotes: 1
Views: 1610
Reputation: 178
You can use "moment" package to format date.
import moment from "moment";
moment(date,"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",true).format("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
Upvotes: 1