React时间转换为具体的年月日上午下午

export default class index extends Component {

constructor() {

super();

this.state = { date: new Date() };

}

componentWillMount() {

this.timer = setInterval(() => { this.setState({ date: new Date() }) }, 1000);

}

componentWillUnmount() {

clearInterval(this.timer);

this.timer = null;

}

render() {

let t = this.state.date;

let year = t.getFullYear();

let month = t.getMonth() + 1;

let day = t.getDay() + 1;

let hour = ((t.getHours() < 10) ? "0" : "") + t.getHours();

let minutes = ((t.getMinutes() < 10) ? "0" : "") + t.getMinutes();

let ifnoon = ‘ ‘ + ((t.getHours() < 12) ? "上午" : "下午") + ‘ ‘;

return (

<div className="header">

<Row className="breadcrumb">

<Col span={4} className="breadcrumb-title">首页</Col>

<Col span={20} className="weather">

<span className="date">{year + ‘/‘ + month + ‘/‘ + day + ifnoon + hour + ‘:‘ + minutes}</span>

</Col>

</Row>

</div>

)

}

}

原文地址:https://www.cnblogs.com/toMe-studio/p/11465235.html

时间: 2024-07-31 16:31:16

React时间转换为具体的年月日上午下午的相关文章

关于时间的操作(JavaScript版)——页面显示格式:年月日 上午下午 时分秒 星期

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

时间操作(JavaScript版)—页面显示格式:年月日 上午下午 时分秒 星期

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

Python中如何把一个UTC时间转换为本地时间

需求: 将20141126010101格式UTC时间转换为本地时间. 在网上搜了好长时间都没有找到完美的解决方案.有的引用了第三方库,这就需要在现网安装第三方的软件.这个是万万不可的.因为真实环境不一定允许你随便使用root用户安装Python模块.最终找到了一个不用外部模块的完美解决方案,放在这里分享给大家. 1 #!/usr/bin/python 2 3 import os,sys,datetime,time 4 from datetime import datetime 5 import

UTC时间转换为本地时间

UTC时间转换为本地时间DATEADD(hour, DATEDIFF(hour,GETUTCDATE(),GETDATE()), OrderDate) <'2015-02-02' DECLARE @LocalDate DATETIME, @UTCDate DATETIME, @LocalDate2 DATETIME SET @LocalDate = GETDATE() SET @UTCDate = DATEADD(hour, DATEDIFF(hour,GETDATE(),GETUTCDATE(

【测试工具】一个将Unix时间转换为通用时间的工具

一个将Unix时间转换为通用时间的工具 演示效果: 点击转换之后变为: 源代码: function calctime2(){ var time = window.document.getElementById("inpTime").value; if ( time == "" ) { alert("时间为空,请重新输入"); return; } if ( isDigit(time) == false ) { alert("时间只能由数字

转自文翼的博客:将本地时间转换为 GMT 时间

在写 RSS 订阅接口的时候,发现最终输出文章的 RSS 时间(GMT时间),在本地上显示的时间和在服务器上显示的时间不一致. 原因是时区不一致,那么在 JavaScript 中,如何将时间转换为统一的时间呢? 1. 查看本地和服务器的时区 通过 date 命令,可以知道: 本地的时区是:GMT+0800 (CST) 服务器的时区是:GMT+0400 (MSK) 首先,需要明确的一点是,文章上的时间是基于本地时间的,也就是说是 GMT+0800 (CST). 2. 代码调试 便于理解,我们来举个

时间转换为Unix时间戳

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Common { public class DateUtils { /// <summary> /// 时间转换为Unix时间戳 /// </summary> /// <param name="date"&g

jquery 的日期时间控件(年月日时分秒)

<!-- import package --> <script type="text/javascript" src="JS/jquery.js"></script> <script type="text/javascript" src="JS/jquery-ui-1.7.3/ui/jquery-ui-1.7.3.custom.js"></script> <sc

js jq插件 显示中文时间戳 刚刚 N分钟前 N小时前 今天 上午 下午

$.fn.extend({ /* ** 时间戳显示为[不久前,刚刚,N分钟前,N小时前,N天前,N周前,N月前,N年N月N日]的处理 ** eg. ** $('1517451000000').commonTimeStamp(); // 2018年02月01日 ** $(new Date('2018-02-01 15:10:00').getTime()).commonTimeStamp(); // 1分钟前 */ "commonTimeStamp": function () { // 补