Thu. Jun 17th, 2021

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

 195 total views,  1 views today

By Susanto Paul

Susanto is an Oracle ACE, a qualified MCA, MBA, and a highly-skilled Senior Oracle Specialist. He is an enthusiastic Blogger and YouTuber who helps learners to solve their complex problems more efficiently. He has 9+ years of experience in multiple technologies like AWS, Oracle ADF, Oracle APEX, Oracle JET, Oracle VBCS, Oracle IDCS, Oracle PL/SQL, Oracle Integration Cloud, Java, JDBC, Servlets, JSP, Spring, Hibernate, HTML5, CSS3, JavaScript, TypeScript, NodesJS, Angular, MySQL, Oracle WebLogic Server, JUnit, JMeter, Selenium Web Driver, etc. He is a certified: Oracle Certified Professional Java SE 6 Programmer, Oracle ADF 11g Certified Implementation Specialist, Oracle Cloud Platform Application Integration 2020 Certified Specialist, Oracle Cloud Infrastructure Foundations 2020 Certified Associate, and Oracle Cloud Infrastructure Developer 2020 Certified Associate

Leave a Reply

Your email address will not be published. Required fields are marked *