-1

var d = new Date();
var h = d.getHour();
var m = d.getMinute();
var s = d.getSecond();

if (h == 12) {
  alert(h + ":" + m + ":" + s + " PM");
} else {
  alert(h + ":" + m + ":" + s + " AM");
}

What should i do? Should i change the d.getMinute() to d.getMin()?

Thank you all

connexo
  • 53,704
  • 14
  • 91
  • 128
  • 2
    Please read the documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#JavaScript_Date_instances . If the browser tells you something like "`undefined` is not a function" then you are trying to access something that doesn't exist. The documentation will tell you what exists, no need to guess. – Felix Kling Jan 19 '19 at 01:56
  • Thank you @FelixKling ! – PIZZZZZZZZZZZA is here Jan 19 '19 at 01:57

1 Answers1

1

The methods are all supposed to be pluralized:

var d = new Date();    
var h = d.getHours();
var m = d.getMinutes();    
var s = d.getSeconds();    
if(h == 12) {
    alert(h+":"+m+":"+s+" PM");
} else {
    alert(h+":"+m+":"+s+" AM");
}

For more more information about the Date methods: W3School

Oguzcan
  • 412
  • 6
  • 20
dtanabe
  • 1,611
  • 9
  • 18
  • 1
    No problem! Additionally there are many options for formatting a date in JavaScript discussed here: https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date – dtanabe Jan 19 '19 at 01:56