javascript - 需要帮助在反应本机应用程序中获取希伯来语日期
问题描述
一般来说,我对原生和 javascript 的反应还是很陌生,但我正在尝试学习如何使用它制作应用程序。我希望能够在我的应用程序中显示当前的希伯来语日期。希伯来历是一种独特的阴阳历,因此获取希伯来日期不能是简单的公历日期本地化。似乎有多个 js 依赖项可以为我提供希伯来语日期(到目前为止,我已经尝试过 hebcal 和 hedate),但没有一个有效。我认为 hebcal 只是与本机反应不兼容,但使用 heDate 我得到一个错误TypeError: Object is not a constructor (evaluating 'new heDate()')
。我可以解决这个问题吗?如果没有,我将如何从网站上提取它?
这是我的代码:
import { setStatusBarBackgroundColor } from "expo-status-bar";
import React, { Component } from "react";
import { View, StyleSheet, Text } from "react-native";
var heDate = require("he-date");
var d = new heDate();
var date = d.getDate();
const Zmanim = () => {
return (
<View style={styles.container}>
<Text style={styles.text}>{date}</Text>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#487dc7",
},
text: {
fontSize: 20,
fontWeight: "bold",
color: "#fff",
},
});
export default Zmanim;
解决方案
图书馆“希伯来日期”似乎适用于计算。https://www.npmjs.com/package/hebrew-date
import React from 'react';
import {Text, View} from 'react-native';
import hebrewDate from 'hebrew-date';
export default function App() {
const date = hebrewDate(new Date())
return (
<View>
<Text>{date.date} {date.month_name} {date.year}</Text>
</View>
);
}
今天的输出(2021 年 5 月 16 日公历)= 5 Sivan 5781
推荐阅读
- react-native - 升级 React Native 后出现“verifyReleaseResources”错误
- sql - SQL Join 两个 a 条件不匹配的表
- c - C中文件读取不正确
- android - 背景中的居中元素与前景中的居中元素不匹配
- css - 如何对齐 bootstrap-vue 下拉按钮项目
- vb.net - 用户的不同日期时间格式导致错误
- javascript - 如何通过 this.id 获得的 ID 将元素附加到另一个元素?
- git - Git 同时在多个包中切换分支
- vue.js - Vue.js test-utils 如何从模块中模拟 getter
- javascript - 如何使用 Nuxt 2 转换 node_modules 中的依赖项?