ReactFix
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • React
  • React Native
  • Programming
  • Object Oriented Programming

Wednesday, November 30, 2022

[FIXED] How to Get Date only or Time only output in react-native

 November 30, 2022     android, datetime, react-native   

Issue

I am developing an app in react-native. I am using an npm package called react-native-modal-datetime-picker for collecting date. But the output i am getting is mixture of date and time 'Fri Feb 17 2017 16:06:00 GMT+0530 (IST)' How cant collect only date in the format format="DD-MM-YY" from this.


Solution

If you have it as an Javascript Date object you could do this:

var day = date.getDate();
var month = date.getMonth();
var year = date.getFullYear();

After that you can format it how you like. Just remember that getMonth() is from (0-11), so you can add one to the result to get it like a "normal" calendar.

var string = day + '-' + month + '-' + year;


Answered By - Danielh
Answer Checked By - - Senaida (ReactFix Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Post Older Post Home

Featured Post

Is Learning React Difficult?

React is difficult to learn, no ifs and buts. React isn't inherently difficult to learn. It's a framework that's different from ...

Total Pageviews

Copyright © ReactFix