Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

date-fns - how to convert date and hr with minute to iso format?

Tags:

date-fns

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

like image 960
3gwebtrain Avatar asked Oct 26 '25 17:10

3gwebtrain


1 Answers

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.

like image 66
Pedro Romano Avatar answered Oct 29 '25 16:10

Pedro Romano



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!