I\'m trying to format a Date String in React Native.
Ex: 2016-01-04 10:34:23
Following is the code I\'m using.
var date = new Date(\"2016-01-
The beauty of the React Native is that it supports lots of JS libraries like Moment.js. Using moment.js would be a better/easier way to handle date/time instead coding from scratch
just run this in the terminal (yarn add moment also works if using React's built-in package manager):
npm install moment --save
And in your React Native js page:
import Moment from 'moment';
render(){
Moment.locale('en');
var dt = '2016-05-02T00:00:00';
return( {Moment(dt).format('d MMM')} ) //basically you can do all sorts of the formatting and others
}
You may check the moment.js official docs here https://momentjs.com/docs/