Search code examples
iosdatetimereact-nativensdate

How to get the Current Date in ReactNative?


I am building my first ReactNative iOS and Android app. I am an iOS coder with Swift and Obj-C. How do I fetch the current date using ReactNative.

Shall I use Native Modules or is there an ReactNative API from which I can get this data ?


Solution

  • The JavaScript runtime in React Native has access to date information just like any other environment. As such, simply:

    new Date()
    

    ... will give you the current date. Here's the MDN on working with dates in JS.

    If you want a good JS library to make working with dates even easier, check out MomentJS.