How to Display JavaScript datetime in 12 hour AM/PM Format? Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Here are different ways to display the datetime in 12 hour format in JavaScript.1. Using toLocaleString() Method In this approach, we will utilize an inbuilt method toLocaleString() to change the format of the given date into AM-PM format. toLocaleString() Method returns a string representation of the date Object. The 2 arguments Locale and options allow for customization of the behaviour of the method. JavaScript let date = new Date(); let n = date.toLocaleString([], { hour: "2-digit", minute: "2-digit", }); console.log(n); Output07:42 AM 2. Using the Native Approach In this approach, we will change the DateTime format by only using native methods. Simply put, we will apply the modulo "%" operator to find the hour in 12-hour format and use the conditional "?:" operator to apply "AM" or "PM". JavaScript let date = new Date(); let hours = date.getHours(); let minutes = date.getMinutes(); // Check whether AM or PM let newformat = hours >= 12 ? "PM" : "AM"; // Find current hour in AM-PM Format hours = hours % 12; // To display "0" as "12" hours = hours ? hours : 12; minutes = minutes < 10 ? "0" + minutes : minutes; console.log(hours + ":" + minutes + " " + newformat); Output3:15 AM 3. Using Intl DateTimeFormat() ConstructorThe Intl.DateTimeFormat object enables language-sensitive date and time formatting. By specifying the appropriate options, we can easily convert the time to a 12-hour format with AM/PM notation. JavaScript let date = new Date(); let formatter = new Intl.DateTimeFormat("en-US", { hour: "2-digit", minute: "2-digit", hour12: true, }); let formattedTime = formatter.format(date); console.log(formattedTime); Output07:42 AM Comment V vishodushaozae Follow Improve V vishodushaozae Follow Improve Article Tags : JavaScript Web Technologies javascript-date JavaScript-Questions Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like