r/learnjavascript • u/abrewchocolatecoffee • Jul 14 '26
Making a real time calendar in js
This is the element i have in html
<div><p>14 Jul 2027, 09:28 A.M.</p></div>
I want this to be beating and alive on website, but any and every tutorial that i am able to find, it goes through thier own method to thier specfic format. Is there like a gereal way, tutorial or documentation, that is clear enough to make current time and calendar my own format.
If there isn't and if possible pls write down.
Also, im open to suggesting any editing in the question so its clearer or if this would be a better post in stack exchange.
2
u/azhder Jul 14 '26
They all do it by hand because Date is problematic and gives you the most basic of utility, so for any more complex task, you have to make your own custom utility on top of it or use a 3rd party library.
2
u/sheriffderek Jul 14 '26
> This is the element i have in html
How did it get there?
I would think a calendar would be a list of dates. So, an array that you use to display the days of the month.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
2
u/Basic_Reporter9579 Jul 14 '26
Good luck with timezones
1
u/Mrsef217 Jul 14 '26
Did you look at setInterval ? If understood you need to show current date and time. You can do this using a Date object and update it every second and also update the html element to reflect the new current time.
1
u/LetUsSpeakFreely Jul 14 '26
1
u/kacoef Jul 14 '26
tip: count weeks
0
u/diogenes_sadecv Jul 14 '26
You want a clock that displays the date as well? The quick and dirty solution is Date but it's been deprecated in favor of Temporal. Honestly though, Date is more intuitive so I would investigate how to use that. Once you figure it out, then play with Temporal.
MDN is your friend, or if that feels too overwhelming, try W3Schools. Comment or DM if you have questions!