JavaScript Date object provides an easy way to work with dates and times in the client-side script. If you want to get the current date or change the format of a date and time, the JavaScript Date object is very useful.
In this tutorial, we will show you how to get the current date and time in JavaScript. Use the following JavaScript code snippet to get the current date and time with Y-m-d
and H:i:s
format.
JavaScript Date object help us to work with dates. Use new Date() to create a new object with current date and time.
var today = new Date();
Get current date from Date object in Y-m-d
format.
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
Get current time from Date object in H:i:s
format.
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
Get current date and time from Date object in Y-m-d H:i:s
format.
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate(); var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds(); var dateTime = date+' '+time;
what about if u want to get specific location, Like Nepal or USA or Canada if you are in different timezone