Retrieving Day Names in PHP

2019-02-16 13:16发布

I need to display to user a list of localized day names (like 'Monday', 'Tuesday', ...) in a form. I know ho to get day name of any date. But is there a particular and fail-proof way to get all day names in an array.

Edit: I could add names of days to my translation file but that is hard to maintain.

标签: php date locale
7条回答
小情绪 Triste *
2楼-- · 2019-02-16 14:23

The "usual" way is to start with a given last day and count up a day on each iteration.

for ($i = 0; $i < 7; $i++) {
  $weekDayNames[] = strftime("%a", strtotime("last sunday +$i day"));
}
查看更多
登录 后发表回答