reactjs - ReactJs:Date().toLocaleTimeString 不起作用
问题描述
目前我开始学习 ReactJs。我想在反应中获取当前时间。但是我使用的方法显示了一些错误。我想获取当前时间。
我尝试了一些类似的问题,但对我没有帮助。
我试过的
import React, { useState } from 'react';
let datte = new Date().toLocaleTimeString;
const Click = () => {
return(
<>
<div className="container mt-5 text-center bg-danger rounded p-5 text-white">
<h2>The current Time is : {datte} </h2>
<button className="btn btn-info btn-lg">Get time</button>
</div>
</>
);
};
export default Click;
我得到的错误
index.js:1 Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.
in h2 (at Click.jsx:13)
in div (at Click.jsx:12)
in Click (at src/index.js:7)
那么我该如何解决这些错误..
谢谢
解决方案
使用这个 toLocaleTimeString();
推荐阅读
- c# - 调试系统.线程
- java - 让计数器只计算字母,而不是空格
- python - 使用子进程调用时 ssh-keygen 引发密码太短错误
- python - python脚本模块中缺少pip.exe
- javascript - 选中多个复选框时,表单字段应与公共字段相应显示
- html - 在孩子占据的空间中隐藏父母背景
- visual-studio - 如何在 VS2019 Enterprise 中分配 RunSettings?
- db2 - AS400 - 解析 JSON 并将字段存储到 DB2 表中
- linux - 模块无法启动 Ansible
- ms-office - 如何访问 Microsoft PowerApp