Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

display am pm in javascript

function formatAMPM(date) {
  var hours = date.getHours();
  var minutes = date.getMinutes();
  var ampm = hours >= 12 ? 'pm' : 'am';
  hours = hours % 12;
  hours = hours ? hours : 12; // the hour '0' should be '12'
  minutes = minutes < 10 ? '0'+minutes : minutes;
  var strTime = hours + ':' + minutes + ' ' + ampm;
  return strTime;
}

console.log(formatAMPM(new Date));
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: relative width and height image react native 
Javascript :: check if string is valid date 
Javascript :: fs.readdir example 
Javascript :: angular timestamp 
Javascript :: disable unused vars 
Javascript :: js make value positive 
Javascript :: hide and show in angular 8 
Javascript :: js decode base64 
Javascript :: jquery scroll to div with offset 
Javascript :: add commas to a number javascript 
Javascript :: how to create a button with react 
Javascript :: how to take a input video on browser using javascript and play it 
Javascript :: javascript rupiah format 
Javascript :: javascript number methods 
Javascript :: javascript remove a specific item from an array 
Javascript :: check if item exists in localstorage javascript 
Javascript :: get request react 
Javascript :: first letter capital in javascript 
Javascript :: js get date from datetime 
Javascript :: push state array react 
Javascript :: how to get contrast from a color using js 
Javascript :: How to access the request body when POSTing using Node.js and Express 
Javascript :: rgb to hex js 
Javascript :: how to check whether a string contains a substring in typescript online 
Javascript :: jquery fade opacity 
Javascript :: immediately invoked function in javascript 
Javascript :: how to make slide js in owl carousel auto 
Javascript :: input radio checked jquery 
Javascript :: jquery debounce 
Javascript :: javascript template strings 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =