PHP星期几数字到星期几的文字 [英] PHP day of week numeric to day of week text

查看:124
本文介绍了PHP星期几数字到星期几的文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能很简单,但我找不到PHP功能来执行此操作...



确定如此

  $ dow_numeric = date('w'); 

将星期日至星期六的星期几0-6的数字日。



  $ dow_text = date('D'); 

给出了一周中文本日的3个字母的缩写(Sun,Mon等) / p>

有没有一个功能或简单的方法来使用 $ dow_numeric 来获取 $ dow_text ?如果我有'0'作为 $ dow_numeric ,我该怎么做 $ dow_text ='Sun'?是的开关语句可以做这个工作,但我正在寻找一个更优雅的解决方案。

解决方案

创建一个数组,将数字DOW映射到文本DOW。

  $ dowMap = array ','星期一','星期二','星期三','星期四','星期五','星期六'); 

如果您需要语言环境支持,请加载某个随机日期的窗口(epoch(0)将为以日期为准),然后在接下来的6天内动态构建道德地图。


This may be really easy but I can't find a PHP function to do this...

OK so

$dow_numeric = date('w');

gives the numeric day of the week 0-6 for Sunday to Saturday.

And

$dow_text = date('D');

gives the 3 letter abbreviation for the text day of the week (Sun, Mon, etc.)

Is there a function or easy way to use $dow_numeric to get $dow_text? If I have '0' as $dow_numeric, how can I make $dow_text = 'Sun'? Yes a switch statement could do the job, but I’m looking for a more elegant solution.

解决方案

Create an array to map numeric DOWs to text DOWs.

$dowMap = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');

If you need locale support, load the dow of some random date (epoch (0) would be a good date for example) and then for the next 6 days and build the dow map dynamically.

这篇关于PHP星期几数字到星期几的文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆