第一个星期六选定的一个月和一年

编程入门 行业动态 更新时间:2024-10-24 14:24:32
本文介绍了第一个星期六选定的一个月和一年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何找到给定月份和年份(日历选择的月份和年份)的第一个星期六?我正在使用PHP。

How could I find the first Saturday for a given month and year (month & year selected by a calender)? I am using PHP.

推荐答案

使用此功能:

<?php /** * * Gets the first weekday of that month and year * * @param int The day of the week (0 = sunday, 1 = monday ... , 6 = saturday) * @param int The month (if false use the current month) * @param int The year (if false use the current year) * * @return int The timestamp of the first day of that month * **/ function get_first_day($day_number=1, $month=false, $year=false) { $month = ($month === false) ? strftime("%m"): $month; $year = ($year === false) ? strftime("%Y"): $year; $first_day = 1 + ((7+$day_number - strftime("%w", @mktime(0,0,0,$month, 1, $year)))%7); return @mktime(0,0,0,$month, $first_day, $year); } // this will output the first saturday of january 2007 (Sat 06-01-2007) echo strftime("%a %d-%m-%Y", get_first_day(6, 1, 2007)); ?>

学分: php

:另一个简短的方法:

使用strtotime()这样:

Use strtotime() like this:

$month = 1; $year = 2007; echo date('d/M/Y',strtotime('First Saturday '.date('F o', @mktime(0,0,0, $month, 1, $year))));

输出:

06/Jan/2007

更多推荐

第一个星期六选定的一个月和一年

本文发布于:2023-06-10 02:02:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/606261.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第一个   一个月   星期

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!