This repository has been archived by the owner on Nov 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Samrith Shankar
committed
Jun 23, 2019
1 parent
aa349bf
commit 519f474
Showing
1 changed file
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,96 @@ | ||
import React from 'react'; | ||
import React, { useState } from 'react'; | ||
import ReactLiveTime from 'react-live-time'; | ||
|
||
export default function App() { | ||
const [date, setDate] = useState(Date.now()); | ||
const [format, setFormat] = useState('isoDateTime'); | ||
const [showSeconds, setShowSeconds] = useState(false); | ||
|
||
const removeMinute = () => { | ||
const __d = new Date(date); | ||
setDate(__d.setMinutes(__d.getMinutes() - 1)); | ||
}; | ||
|
||
const removeHour = () => { | ||
const __d = new Date(date); | ||
setDate(__d.setHours(__d.getHours() - 1)); | ||
}; | ||
|
||
const resetDate = () => { | ||
setDate(Date.now()); | ||
}; | ||
|
||
const changeFormat = e => { | ||
setFormat(e.target.value); | ||
}; | ||
|
||
const changeShowSeconds = e => { | ||
setShowSeconds(e.target.checked); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<ReactLiveTime time={new Date()} /> | ||
<p>DATE: {new Date(date).toLocaleString()}</p> | ||
<p> | ||
<ReactLiveTime | ||
time={date} | ||
format={format} | ||
showSeconds={showSeconds} | ||
renderer={({ text, status, diff }) => ( | ||
<span> | ||
{text}, {status}, {diff} | ||
</span> | ||
)} | ||
/> | ||
</p> | ||
<p> | ||
Remove hours or minutes: | ||
<button onClick={removeMinute}>Minute</button> | ||
<button onClick={removeHour}>Hour</button> | ||
<button onClick={resetDate}>Reset Date</button> | ||
<input | ||
type="text" | ||
onChange={changeFormat} | ||
value={format} | ||
placeholder="Add format" | ||
/> | ||
<label htmlFor="showSeconds"> | ||
<input | ||
type="checkbox" | ||
name="showSeconds" | ||
onChange={changeShowSeconds} | ||
value={showSeconds} | ||
/> | ||
Show seconds? | ||
</label> | ||
</p> | ||
<p> | ||
For formatting values, check out{' '} | ||
<a | ||
href="https://github.com/felixge/node-dateformat#mask-options" | ||
rel="noopener noreferrer" | ||
target="_blank" | ||
> | ||
mask options | ||
</a>{' '} | ||
and{' '} | ||
<a | ||
href="https://github.com/felixge/node-dateformat#named-formats" | ||
rel="noopener noreferrer" | ||
target="_blank" | ||
> | ||
named formats | ||
</a> | ||
. Formatting powered by{' '} | ||
<a | ||
href="https://github.com/felixge/node-dateformat" | ||
rel="noopener noreferrer" | ||
target="_blank" | ||
> | ||
dateformat | ||
</a> | ||
. | ||
</p> | ||
</div> | ||
); | ||
} |