inherit
169267
0
Sept 4, 2023 1:07:10 GMT -8
Mike
Praise God Almighty!
1,501
July 2011
riccetts
|
Post by Mike on Feb 19, 2014 19:34:28 GMT -8
I have my code here.
$(document).ready(function(){ function getTime() { var d = new Date; var hours = d.getHours(); var mins = d.getMinutes(); if(hours > 12){ var hour = (hours - 12); var ampm = "PM"; } if(mins < 10) { mins = '0'+mins; } else{ var hour = hours; var ampm = "AM"; } return hour + ":" + mins+ampm; } setInterval(function(){ $("h1").html(getTime()) }, 500); });
I want to make it standard time instead of military time. Can anybody help with this problem?
|
|
inherit
Official Code Helper
65613
0
1
Sept 28, 2022 13:12:14 GMT -8
Chris
8,751
December 2005
horace
|
Post by Chris on Feb 19, 2014 20:33:43 GMT -8
No sense reinventing the wheel, Proboards has already written a function for that. You could get the format you want by calling Proboards' function instead of your getTime function$.formatTime('hh:mm:ss p', new Date()) would yield something like "10:32:21 pm"
The format string can be constructed using the following modifiers if you wish to customize
|
|
inherit
169267
0
Sept 4, 2023 1:07:10 GMT -8
Mike
Praise God Almighty!
1,501
July 2011
riccetts
|
Post by Mike on Feb 19, 2014 21:17:40 GMT -8
Thank you for this. ChrisHow would you setup the modifiers? (pm & am)
|
|
inherit
Official Code Helper
65613
0
1
Sept 28, 2022 13:12:14 GMT -8
Chris
8,751
December 2005
horace
|
Post by Chris on Feb 19, 2014 21:44:21 GMT -8
The format I gave you in the example already sets it up for am/pm by specifying a "p"'hh:mm:ss p' That formatting string specifically says create a format of hours:minutes:seconds am/pm with leading zeroes if single digit. The lowercase "p", as the list of modifiers I posted shows, will produce a lowercase am or pm, if you wanted uppercase AM or PM you would use the uppercase "P", if you wanted no am/pm you would not put a "p" at all
|
|
inherit
169267
0
Sept 4, 2023 1:07:10 GMT -8
Mike
Praise God Almighty!
1,501
July 2011
riccetts
|
Post by Mike on Feb 23, 2014 7:44:21 GMT -8
ChrisI'm not sure how to set this up. pb.function(){ $.formatTime('hh:mm:ss p', new Date()); $.formatTime==('h1')}
I tried this and.... nothing
|
|
inherit
Official Code Helper
65613
0
1
Sept 28, 2022 13:12:14 GMT -8
Chris
8,751
December 2005
horace
|
Post by Chris on Feb 23, 2014 8:24:03 GMT -8
You were doing $("h1").html(getTime()) and asking for assistance with the getTime function you created Mike. What I said was Proboards already wrote that function so you didn't need to try and create one on your own just use the one already made. $("h1").html($.formatTime('hh:mm:ss p', new Date())).
You do not need to create a getTime function at all
|
|
inherit
169267
0
Sept 4, 2023 1:07:10 GMT -8
Mike
Praise God Almighty!
1,501
July 2011
riccetts
|
Post by Mike on Feb 23, 2014 9:06:06 GMT -8
ChrisDo you mean I don't need any thing but -> $("h1").html($.formatTime('hh:mm:ss p', new Date())) in my header along with my html code?
|
|