php根据出生日期计算年龄 生肖 星座程序

例1

 代码如下 复制代码

function getAge($birthday) {
 $age = 0;
 $year = $month = $day = 0;

 if (is_array($birthday)) {
  extract($birthday);
 } else {
  if (strpos($birthday, '-') !== false) {
   list($year, $month, $day) = explode('-', $birthday);
   $day = substr($day, 0, 2); //get the first two chars in case of '2000-11-03 12:12:00'
  }
 }

 $age = date('Y') - $year;
 if (date('m') < $month || (date('m') == $month && date('d') < $day)) $age--;
 return $age;
}

例2

 代码如下 复制代码

function age($birth) {
 $age = array();
 //$now = date('Ymd');
 $now = "20110228";
 //分解当前日期为年月日
 $nowyear = (int) ($now / 10000);
 $nowmonth = (int) (($now % 10000) / 100);
 $nowday = $now % 100;
 
 
 //分解出生日期为年月日
 $birthyear = (int) ($birth / 10000);
 $birthmonth = (int) (($birth % 10000) / 100);
 $birthday = $birth % 100;
 
 $year  = $nowyear - $birthyear;
 if ($birthmonth>$nowmonth){
  $year--;
 }else if($birthmonth==$nowmonth){
  if($birthday==29&&$birthmonth=2){
/*    if($nowyear>3200||($nowyear%3200==0&&$nowyear%172800==0)){
    if($birthday>$nowday){
     $year--;
    }
   }else if($nowyear==3200){
    if (($birthday>$nowday)&&$nowday!=28){
     $year--;
    }
   }else */
   if ($nowyear%400==0||(($nowyear%4==0)&&($nowyear%100!=0))){
    if($birthday>$nowday){
     $year--;
    }
   }
  }
 }
 
 return $year;
 
 
 
 
}

根据生日计算年龄 星座 生肖

水瓶座'=>'(1/22-2/21)',   '双鱼座'=>'(2/22-3/21)',

'白羊座'=>'(3/22-4/21)',   '金牛座'=>'(4/22-5/21)',

'双子座'=>'(5/22-6/21)',   '巨蟹座'=>'(6/22-7/21)',

'狮子座'=>'(7/22-8/21)',   '处女座'=>'(8/22-9/21)',

'天秤座'=>'(9/22-10/21)',  '天蝎座'=>'(10/22-11/21)',

'射手座'=>'(11/22-12/21)',  '摩羯座'=>'(12/22-1/21)'

 代码如下 复制代码

[font=Arial]<?php[/font]

[font=Arial]/**

 * 根据生日中的月份和日期来计算所属星座

 *

 * @param int $birth_month

 * @param int $birth_date

 * @return string

 */

function get_constellation($birth_month,$birth_date)

{

 //判断的时候,为避免出现1和true的疑惑,或是判断语句始终为真的问题,这里统一处理成字符串形式

 $birth_month = strval($birth_month);

 

 $constellation_name = array(

      '水瓶座','双鱼座','白羊座','金牛座','双子座','巨蟹座',

      '狮子座','处女座','天秤座','天蝎座)','射手座','摩羯座'

      );

 

 if ($birth_date <= 22)

 {

  if ('1' !== $birth_month)

  {

   $constellation = $constellation_name[$birth_month-2];

  }

  else

  {

   $constellation = $constellation_name[11];

  }

 }

 else

 {

  $constellation = $constellation_name[$birth_month-1];

 }

 

 return $constellation;

}[/font]

 

 

[font=Arial]/**

 * 根据生日中的年份来计算所属生肖

 *

 * @param int $birth_year

 * @return string

 */

function get_animal($birth_year)

{

 //1900年是子鼠年

 $animal = array(

    '子鼠','丑牛','寅虎','卯兔','辰龙','巳蛇',

    '午马','未羊','申猴','酉鸡','戌狗','亥猪'

    );

 

 $my_animal = ($birth_year-1900)%12;

 return $animal[$my_animal];

}[/font]

时间: 2024-08-31 10:11:35

php根据出生日期计算年龄 生肖 星座程序的相关文章

php根据生日计算年龄/生肖/星座实例

//计算年龄  代码如下 复制代码 function birthday($mydate){     $birth=$mydate;     list($by,$bm,$bd)=explode('-',$birth);     $cm=date('n');     $cd=date('j');     $age=date('Y')-$by-1;     if ($cm>$bm || $cm==$bm && $cd>$bd) $age++;     return $age; //e

python根据出生日期返回年龄的方法_python

本文实例讲述了python根据出生日期返回年龄的方法.分享给大家供大家参考.具体实现方法如下: def CalculateAge(self, Date): '''Calculates the age and days until next birthday from the given birth date''' try: Date = Date.split('.') BirthDate = datetime.date(int(Date[0]), int(Date[1]), int(Date[2

jQuery实现根据生日计算年龄 星座 生肖_jquery

<html> <head> <title></title> <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> <script type="text/javascript"> //根据输入的生日自动获取星座,生肖和年龄. var year = new Array("

根据身份证号码计算出生日期、年龄、性别(18位) 根据入职时间计算工龄。_正则表达式

1.根据身份证号码计算出生日期.年龄.性别(18位) 复制代码 代码如下: //获取输入身份证号码 var UUserCard = $("#UUserCard").val(); //获取出生日期 //UUserCard.substring(6, 10) + "-" + UUserCard.substring(10, 12) + "-" + UUserCard.substring(12, 14); //获取性别 if (parseInt(UUser

php计算年龄精准到年月日的程序

这篇文章主要介绍了php计算年龄精准到年月日的方法,涉及php操作日期与字符串的相关技巧,非常简单实用,需要的朋友可以参考下 本文实例讲述了php计算年龄精准到年月日的方法.分享给大家供大家参考.具体如下:  $ni) {       $not_birth = 1;       $tmp = array($byear, $bmonth, $bday);       list($byear, $bmonth, $bday) = array($year, $month, $day);       l

oracle 如何分岁/月等为单位计算年龄?

问题描述 oracle 如何分岁/月等为单位计算年龄? 有oracle一张表表中有一出生日期字段为date 类型是,现要建立一个视图 oracle 表如下 id---(varchar2(10)) date_of_birth---(date) 05576767 1957-3-28 05563743 ? ? ? ? ?2013-3-27 05563744 ? ? ? ? ?2013-7-15 05563745 ? ? ? ? ?2013-6-7 05563741? ? ? ? ? ?2010-11-

使用prony算法计算电力系统频率的程序交流

问题描述 使用prony算法计算电力系统频率的程序交流 10C 初次使用prony算法,希望能有热心小伙伴帮帮忙啦~~!必重谢!! 解决方案 百度文库好像有一份,c++编的

炉膛火焰温度的计算--单色测温法的程序代码

问题描述 炉膛火焰温度的计算--单色测温法的程序代码 单色测温法/双色测温法,请给个思路,程序代码怎么写?matlab源程序代码的编写,单色测温法的程序代码,如何建立温度场与火焰颜色的关系模型?

python根据出生日期返回年龄的方法

 这篇文章主要介绍了python根据出生日期返回年龄的方法,实例分析了Python时间操作的技巧,非常具有实用价值,需要的朋友可以参考下     本文实例讲述了python根据出生日期返回年龄的方法.分享给大家供大家参考.具体实现方法如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 def CalculateAge(self, Date): '''Calculates the age and days