spell out the time
-
I would like help. (duh). on my site i want to present the time in a format where the numbers are spelled out. like two o’clock and thirty minutes PM. can anyone tell me how to do this with the_date() or any other wordpress tag?
-
I’m not much of a WordPress maven, but since nobody answered your question yet I thought I’d give it a try.
I found this thread, which mentions these PHP codes.
That page lists examples like this:
The time is <?php print date("H:i") ?>.
That means it's <?php print date("i") ?>
minutes past <?php print date("H") ?> o'clock.Which will give you an output like this:
The time is 15:26. That means it’s 26 minutes past 15 o’clock.
I tried it on my site and it worked, but it gave me output just like the example: “15 o’clock,” rather than “3 o’clock.”
The other URL mentioned in the thread says lower case “g” will give you a “12-hour format of an hour without leading zeros” and I tried this:
The time is <?php print date("g:i") ?>.
That means it's <?php print date("i") ?>
minutes past <?php print date("g") ?> o'clock.And I got:
The time is 3:26. That means it’s 26 minutes past 3 o’clock.
I hope this helps.
Converting numbers to words can be done, but it’s not easy. There are a few ways I know of to do this in PHP without writing everything from scratch. One involves the PEAR Numbers_Words package:
http://pear.php.net/package/Numbers_Words
There’s also a third-party PHP class called Numbers2Words. You can search for it through Google:
thanks guys ill try these out
well im checking out te numbers2words.php, i’ve got to figure out how to properly use it, seeing as how php isn’t my forte, but i shal prevail.
ok this is turning out to be alot easier than i thought. First i had to drop the numbers2words.php into the plugins foloder along with runphp (im testing it in my posts). now ive just gotta figure out how to take the date and turn it into words :p
this is what im trying:
<?
include(‘numberstowords.php’);
$bob=the_time(‘g’);
$NW= new numberstowords();
echo $NW->n2w($bob).”\n”;
?>but i’m getting 12 instead of twelve
any ideas?
I couldn’t find the absolutely antique script I had years back that did this sort of thing, sorry. You do realize that this is seriously annoying though, having to parse words instead of simply see the time?
Can you paste the source code right here http://pastebin.com ?
yes, it’s ment to be rather annoying. :p
here it is
http://pastebin.com/299458let me add that normally to get it to work, you use
<?
include(‘numberstowords.php’);
$NW= new numberstowords();
echo $NW->n2w(12).”\n”;
?>but where that 12 is i want to put the time variable.
your code works for me; have no clue why it doesn’t work for you
with the variable or just with numbers?
both
really? could you send me a link of it working? it really just isn’t working for me. where are you putting it?
bump
anyone else get this to work?
The topic ‘spell out the time’ is closed to new replies.