Use the following JavaScript code to get 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 = new Date(); var mn = ('0' + (date.getMonth() + 1)).slice(-2); var dt = ('0' + date.getDate()).slice(-2); var yr = date.getFullYear(); var date = yr+'-'+mn+'-'+dt;
Get current time from Date object in H:i:s format.
var time = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
Get current date and time from Date object in Y-m-d H:i:s format.
var dateTime = date+' '+time;
You might also like:
Convert and download html to pdf without saving file28-10-2018 node js convert html to pdf pdf download pdf without saving |
How to search text in string using php ?29-10-2017 php search string search |
How to upload file by using request module18-03-2017 request module node js |
Convert Time 24 hrs to 12 hrs format In javascript12-03-2017 date javascript 12hrs convert |
Filter for insert HTML in Angular Js06-03-2017 filter show html angular js html |