How can I format the date in react?

Viewed 29

I find myself with the difficulty that I cannot format the date in react, the following code was written in VUE JS and it ran perfectly. I would like someone to help me understand this concept please. The code is the following :

import spanish from 'date-fns/locale/es';
import parseISO from 'date-fns/parseISO'
import axios from 'axios';

<ListItem
   style={styles.list}
   title={<Text>{info.item.name}</Text>}
   description={<Text style={styles.list}>{`${info.item.description}`}</Text>}
   date={<Text>{format((parseISO(info.item.date)), 'dd/MMMM/yy', {locale: spanish})} 
         </Text>}
   accessoryLeft={renderItemIcon}
    onPress={() => navigation.push('Validator', {data: info.item, email: email})}
    >
      
</ListItem>
1 Answers
import * as React from "react";
import spanish from "date-fns/locale/es";
import parseISO from "date-fns/parseISO";
import format from "date-fns/format";


export default function App() {
  return (
    <div>
              {format((parseISO("2022-01-01T16:00:00-05:00")), "dd-MMMM-yyyy",{ locale: spanish })}
    </div>
  );
}

this is my piece of code, and this is working totally fine result 02-enero-2022

Related