Last active
September 20, 2021 09:37
-
-
Save maxmckenzie/d345b47f261ef5716cc7618c2c82fd29 to your computer and use it in GitHub Desktop.
Revisions
-
maxmckenzie revised this gist
Sep 20, 2021 . 1 changed file with 8 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,16 @@ const [myDate, setMyDate] = useState() const pad2 = (num: number): string => num < 10 ? '0' + num : num.toString(); const utcAsLocalString = (date: Date | undefined): string | undefined => { if (date == null) return undefined; return (date.getFullYear() + '-' + pad2(date.getMonth()) + '-' + date.getDate() + 'T' + pad2(date.getHours()) + ':' + pad2(date.getMinutes()) + ':' + pad2(date.getSeconds())) } <input type="datetime-local" class="form-control" onChange={(e) => setMyDate(new Date((e.target as any).value))} value={myDate ? utcAsLocalString(myDate) : null} onFocus={() => {}} /> -
maxmckenzie created this gist
Sep 20, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ const [myDate, setMyDate] = useState() <input type="datetime-local" class="form-control" onChange={(e) => setMyDate(new Date((e.target as any).value))} value={myDate ? myDate.toISOString().split('.')[0] : null} onFocus={() => {}} />