Monday, June 3, 2024
157
rated 0 times [  163] [ 6]  / answers: 1 / hits: 22829  / 8 Years ago, fri, february 19, 2016, 12:00:00

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?


More From » react-native

 Answers
92

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))


[#63262] Wednesday, February 17, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
johnnyblaynes

Total Points: 667
Total Questions: 121
Total Answers: 102

Location: Anguilla
Member since Sat, Jan 23, 2021
3 Years ago
johnnyblaynes questions
;