Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to get current Date and Time using JavaScript

How To Get Current Date And Time Using JavaScript

DotNetTec
How to get current Date and Time using JavaScript

In this article, we will learn about javascript get current date and time formatted. Use the following JavaScript code to get current date and time with Y-m-d and H:i:s format.

    • Must read open new tab in javascript

JavaScript Date Object helps us to work with dates. Use new Date() to create a new object with the 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;

For more details refer to JavaScript Get Date Methods

Conclusion

I hope you liked this article about how to get current Date in JavaScript. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

How to get current Date and Time using JavaScript
Ravi Kumar



This post first appeared on Asp Dot Net Tricks And Tips, Dot Net Coding Tips, Google Maps API Developer, please read the originial post: here

Share the post

How to get current Date and Time using JavaScript

×

Subscribe to Asp Dot Net Tricks And Tips, Dot Net Coding Tips, Google Maps Api Developer

Get updates delivered right to your inbox!

Thank you for your subscription

×