Skip to content

Instantly share code, notes, and snippets.

@tonysaffo
Created December 12, 2018 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonysaffo/7569496877c77ec940b6b970603d8c96 to your computer and use it in GitHub Desktop.
Save tonysaffo/7569496877c77ec940b6b970603d8c96 to your computer and use it in GitHub Desktop.
Use moment.js in react
import React, {Component} from 'react'
import Moment from 'moment/min/moment-with-locales'
import './Infoblock.css'
export default class Infoblock extends Component{
state = {
hasHt: true,
date: Date.now(),
lessons: {
current: 1,
all: 12
}
}
getDate = () => {
return Moment(this.state.date).locale('ru').format('D MMMM, h:mm')
}
render() {
return (
<div className="infoblock">
{this.state.hasHt ? <div className="infoblock__ht-button">Домашнее задание</div> : null}
<div className="infoblock__close-lesson">
<div className="title">
<div className="icon"></div>
<div className="text">Ближайшее занятие</div>
</div>
<div className="date">{this.getDate()}</div>
<div className="info">{this.state.lessons.current} занятие из {this.state.lessons.all}</div>
</div>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment