Ask coding questions

← Back to all posts
How to add current time
sn236

How do I add the current time of the user in html,css,js.

Voters
sn236
Comments
hotnewtop
sn236

I found it.

SixBeeps

Use Date.now() in JS.

EDIT: Combine with Date.getTimezoneOffset() to get time in local timezone.

sn236

@SixBeeps I am not that good with js, so can you give me an example or can you give the code

SixBeeps

@sn236 My bad, it looks like Date.now() doesn't return a date like I remembered. Instead, construct a new Date object to get the current date in local time.

sn236

@SixBeeps It works, but not as I expected. I want the time to be displayed on the output screen.