将时间输出为单词,如“One O'Clock PM”在 PHP 中
我正在开发一个相对初级的项目,需要使用文本到语音引擎来读取当前时间。 PHP 允许我以多种方式输出当前时间。但是,我需要将时间输出为单词。例如,13:00 应输出为“下午一点”等。另一个示例,01:23 应输出为“凌晨一点二十三分”。
我搜索了一些脚本,并尝试使用我极其业余的 PHP 技能来完成此任务,但到目前为止我无法完成该任务。
有谁知道用 PHP 编写的现有脚本可以做到这一点?我们要做的就是读取系统时间,应用时区偏移量,然后将得到的时间并以单词的形式输出。我可以提供任何需要的澄清。
谢谢你!
I'm working on a relatively rudimentary project which requires using a text-to-speech engine to read the current time. PHP will allow 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个 PEAR 包 可以将数字翻译成单词(但请注意,我还没有使用它亲自)。
您可以添加一些额外的逻辑,将
00
翻译为“o'clock”,并从date("A")
获取 AM 或 PM(或者检查小时是否为> 12)。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 fromdate("A")
(or check if the hour is > 12).我认为您可以通过标准 PHP 库获得大部分功能:
请参见此处: https://www.php.net/manual/en/function.date.php
I reckon you can get most of the way with the standard PHP libs:
See here: https://www.php.net/manual/en/function.date.php