Chipe
Chipe

Reputation: 4801

React Native New Date string

I am using react-native-calendar-picker. Initially when my app data loads, if there isn't a date stored that was picked, I assign the specific array with new Date() which returns something like this: Thu Feb 18 2016 22:58:12 GMT-0700 (MST). Once the user updates the date I store the new date in React Native's AsyncStorage which has a value something like this: Mon Feb 29 2016 00:00:00 GMT-0700 (MST)

However, once the app reloads the date value is returned like this: "2016-02-29T07:00:00.000Z". The react-native-calendar-picker uses the date formatted like: Mon Feb 29 2016 00:00:00 GMT-0700 (MST)

Is there a way to get the date formatted back to this way?

Upvotes: 2

Views: 25002

Answers (1)

everlasto
everlasto

Reputation: 4930

Try,

String formatted = new Date("2016-02-29T07:00:00.000Z").toString();

Precisely be aware of data types,

new Date() would return a Date object. (2016-02-19T13:42:17.975Z)

new Date().toString() would return a formatted date string. (Fri Feb 19 2016 19:12:17 GMT+0530 (IST))

Upvotes: 8

Related Questions