I am getting a value as 15/07/2019, 18 : 07 - it contains date and hr with minute.
But I would require to send backend as ISO format. how to do with date-fns framewroks? any one help me?
here is the format I am looking for:
2019-07-19T07:37:06.413Z
any one help me?
Thanks in advance
To obtain the ISO8601 string representation of a date you don't need date-fns. You can simply use the Date.toISOString method. For example:
> new Date().toISOString()
'2019-09-02T11:54:53.506Z'
Or if you need to parse the date (date-fns objects have all the methods from Date):
> import { parse } from 'date-fns'
> parse('15/07/2019 18:07', 'dd/MM/yyyy HH:mm', new Date()).toISOString()
'2019-07-15T17:07:00.000Z'
Note that the parsed date is assumed to be in the local time zone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With