How to get current Date and Time using JavaScript || JavaScript Date Formats

JavaScript date time formats image

This tutorial shows, how can you get the current date and time in JavaScript. Use the following JavaScript code to get current date and time with Y-m-dand H:i:s format. JavaScript Date object help us to work with date type of strings. Use new Date() to create a new object with current date and time. var today = new Date(); You can get current date from Date object in Y-m-d format. var date = today.getFullYear()+’-‘+(today.getMonth()+1)+’-‘+today.getDate(); You can get current time from Date object in H:i:s format. var time = today.getHours() + “:” + today.getMinutes() + “:” + today.getSeconds(); You can …