如何在ReactNative中获取当前日期? [英] How to get the Current Date in ReactNative?

查看:152
本文介绍了如何在ReactNative中获取当前日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建我的第一个ReactNative iOS和Android应用程序.我是使用Swift和Obj-C的iOS编码器.如何使用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.

我应该使用本机模块还是我可以从中获取此数据的ReactNative API?

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

推荐答案

React Native中的JavaScript运行时可以像访问其他环境一样访问日期信息.因此,只需:

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

new Date()

...将为您提供当前日期.此处是MDN ,用于在JS中处理日期.

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

如果您希望一个好的JS库使日期处理变得更加容易,请查看 MomentJS .

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

这篇关于如何在ReactNative中获取当前日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆