开发者

Output time as words, as in "One O'Clock PM" in PHP

I'm working on a relatively rudimentary project which requires using a text-to-speech engine to read the current time. PHP will allo开发者_JAVA百科w me to output the current time in many ways. However, I need to output the time as words. For example, 13:00 should output as "one o'clock pm" and so forth. Another example, 01:23 should output as "one twenty three am".

I've searched for some scripts, and attempted to use my terribly amateurish PHP skills to accomplish this, but so far I am unable to complete the task.

Does anyone know of an existing script, written in PHP, that can do this? All we're looking to do is read the system time, apply an offset for time zone, then take the resulting time and output as words. I can give any clarification needed.

Thank you!


There is a PEAR package that translates numbers to words (note however that I haven't used it personally).

You could add in some extra logic to translate 00 as "o'clock", and get AM or PM from date("A") (or check if the hour is > 12).


I reckon you can get most of the way with the standard PHP libs:

echo date('l F j, Y g:ia') . "\n";

See here: http://uk3.php.net/manual/en/function.date.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜