Requirement: I have a requirement where I want to convert the System Date in YYYY-MM-DD_HH:MM:SS format using JavaScript.
Solution: For the solution of the above requirement we will use the below JavaScript code.
define([], function() {
'use strict';
var PageModule = function PageModule() {};
PageModule.prototype.uploadFileName = function() {
var current_datetime = new Date();
var formatted_date = current_datetime.getFullYear() + "-" +
appendLeadingZeroes(current_datetime.getMonth() + 1) + "-" +
appendLeadingZeroes(current_datetime.getDate()) + "_" +
appendLeadingZeroes(current_datetime.getHours()) + ":" +
appendLeadingZeroes(current_datetime.getMinutes()) + ":" +
appendLeadingZeroes(current_datetime.getSeconds());
return formatted_date;
};
function appendLeadingZeroes(n) {
if (n <= 9) {
return "0" + n;
}
return n
}
return PageModule;
});Hence, the solution to our requirement.
If you like the post please comment, share, and do join me on Facebook. Please subscribe to my YouTube Channel for video tutorials.
Thanks & Regards,
Susanto Paul
536 total views, 1 views today