You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
< ? php
class Tools
{
//查询某天是星期几
public static function GetWeekName ( $date )
{
$dayOfWeek = date ( 'N' , strtotime ( $date )); // 获取星期几, 1代表星期一, 7代表星期日
$weekname = '' ;
switch ( $dayOfWeek ) {
case 1 :
$weekname = " 星期一 " ;
break ;
case 2 :
$weekname = " 星期二 " ;
break ;
case 3 :
$weekname = " 星期三 " ;
break ;
case 4 :
$weekname = " 星期四 " ;
break ;
case 5 :
$weekname = " 星期五 " ;
break ;
case 6 :
$weekname = " 星期六 " ;
break ;
case 7 :
$weekname = " 星期日 " ;
break ;
default :
$weekname = " 无效日期 " ;
}
return $weekname ;
}
//计算年龄,返回年龄 如 31
public static function calculateAge ( $birthdate ) {
$birthdate = new DateTime ( $birthdate );
$currentDate = new DateTime ();
$age = $currentDate -> diff ( $birthdate ) -> y ;
return $age ;
}
//计算年龄,返回年龄 如 31岁3月3天
public static function calculateAgeText ( $birthdate ) {
$birthdate = new DateTime ( $birthdate );
$currentDate = new DateTime ();
$ageDiff = $currentDate -> diff ( $birthdate );
$years = $ageDiff -> y ;
$months = $ageDiff -> m ;
$days = $ageDiff -> d ;
$ageString = " " ;
if ( $years > 0 ) {
$ageString .= $years . " 岁 " ;
}
if ( $months > 0 ) {
$ageString .= $months . " 月 " ;
}
if ( $days > 0 ) {
$ageString .= $days . " 天 " ;
}
return $ageString ;
}
}