Skip to content
← Back to Community
How to add current time
Profile icon
sn236

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

Voters
Profile icon
sn236
Comments
hotnewtop
Profile icon
sn236

I found it.

Profile icon
SixBeeps

Use Date.now() in JS.

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

Profile icon
sn236

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

Profile icon
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.

console.log(new Date())
Profile icon
sn236

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