-4

I am getting sometimes '4 PM' or 'PM' for the itemDate string. if itemDate has the value of 'PM' then I should not display anything to my HTML. If i get the value as '4 PM' then I should display that time value.

itemDate = '4 PM'

itemDate ='PM'

P.S : 4 PM is an example time string and it may be 12 AM too.

How do i do the parsing using javascript for my above request?

omarjmh
  • 13,632
  • 6
  • 34
  • 42
user6131488
  • 85
  • 1
  • 13

1 Answers1

0

parseInt gets the value of an integer if it's the first thing in a string, it sounds very convenient in your case since you can just get the number, check if it's there, then act accordingly.

numeric = parseInt(itemDate);

if (typeof(numeric)=="number"){
    alert(itemDate);
}

You might also want to check this

Community
  • 1
  • 1
Remysc
  • 187
  • 6